diff --git a/blueprint.dat b/blueprint.dat index 8f5855e0..01c9560f 100644 Binary files a/blueprint.dat and b/blueprint.dat differ diff --git a/config.lua b/config.lua index 802dec12..76344f39 100644 --- a/config.lua +++ b/config.lua @@ -11,6 +11,5 @@ Event.register(-1, function() global.scenario.config.mapsettings.spiral_land_width = 70 -- width of land in spiral global.scenario.config.mapsettings.spiral_water_width = 70 -- width of water in spiral global.scenario.custom_functions = {} - global.map_layout_name = "HolyLand" end) diff --git a/control.lua b/control.lua index 4a5fb53d..f637aee0 100644 --- a/control.lua +++ b/control.lua @@ -4,6 +4,7 @@ require "config" require "locale/utils/utils" require "base_data" require "info" +require "player_list" require "poll" require "band" require "fish_market" @@ -12,6 +13,7 @@ require "score" require "map_layout" + function player_joined(event) local player = game.players[event.player_index] player.insert { name = "raw-fish", count = 4 } @@ -26,8 +28,9 @@ function player_joined(event) --player.insert { name = "substation", count = 16 } --player.insert { name = "logistic-chest-passive-provider", count = 16 } --player.insert { name = "power-armor", count = 1 } - player.print("Welcome to our Server. You can join our Discord at: discord.gg/RedMew") + player.print("Welcome to our Server. You can join our Discord at: discord.me/redmew") player.print("And remember.. Keep Calm And Spaghetti!") + --game.speed=1 end function walkabout(player_name, distance) @@ -40,13 +43,23 @@ function walkabout(player_name, distance) if distance == "close" then distance = math.random(3000, 7000) + else + if distance == "far" then + distance = math.random(7000, 11000) + else + if distance == "very far" then + distance = math.random(11000, 15000) + else + game.print("Walkabout failed.") + return + end + end end - if distance == "far" then - distance = math.random(7000, 11000) - end - if distance == "very far" then - distance = math.random(11000, 15000) - end + + + + + local x = 1 while game.players[x] ~= nil do diff --git a/fish_market.lua b/fish_market.lua index fa0a5e15..6f12af86 100644 --- a/fish_market.lua +++ b/fish_market.lua @@ -1,5 +1,5 @@ --[[ -Hello there script explorer! +Hello there script explorer! With this you can add a "Fish Market" to your World You can earn fish by killing alot of biters or by mining wood, ores, rocks. @@ -7,8 +7,18 @@ To spawn the market, do "/c market()" in your chat ingame as the games host. It will spawn a few tiles north of the current position where your character is. ---MewMew--- + + +!! now with speed boost item addon from air20 !! + +to be added(maybe) +fix pet health at refresh +make pet faster +make pet follow you moar --]] + + function market() local radius = 10 local surface = game.surfaces[1] @@ -24,12 +34,12 @@ function market() end end end - + local player = game.players[1] - + local market_location = {x = player.position.x, y = player.position.y} market_location.y = market_location.y - 4 - + -- create water around market local waterTiles = {} for i = -4, 4 do @@ -40,45 +50,34 @@ function market() surface.set_tiles(waterTiles) local market = surface.create_entity{name="market", position=market_location, force=force} market.destructible = false - + + market.add_market_item{price={{"raw-fish", 10}}, offer={type="give-item", item="exoskeleton-equipment"}} + market.add_market_item{price={{"raw-fish", 25}}, offer={type="give-item", item="small-plane"}} market.add_market_item{price={{"raw-fish", 1}}, offer={type="give-item", item="rail", count=2}} market.add_market_item{price={{"raw-fish", 2}}, offer={type="give-item", item="rail-signal"}} market.add_market_item{price={{"raw-fish", 2}}, offer={type="give-item", item="rail-chain-signal"}} market.add_market_item{price={{"raw-fish", 15}}, offer={type="give-item", item="train-stop"}} market.add_market_item{price={{"raw-fish", 75}}, offer={type="give-item", item="locomotive"}} - market.add_market_item{price={{"raw-fish", 250}}, offer={type="give-item", item="small-plane"}} market.add_market_item{price={{"raw-fish", 30}}, offer={type="give-item", item="cargo-wagon"}} market.add_market_item{price={{"raw-fish", 1}}, offer={type="give-item", item="red-wire", count=2}} market.add_market_item{price={{"raw-fish", 1}}, offer={type="give-item", item="green-wire", count=2}} market.add_market_item{price={{"raw-fish", 3}}, offer={type="give-item", item="decider-combinator"}} market.add_market_item{price={{"raw-fish", 3}}, offer={type="give-item", item="arithmetic-combinator"}} market.add_market_item{price={{"raw-fish", 3}}, offer={type="give-item", item="constant-combinator"}} - market.add_market_item{price={{"raw-fish", 7}}, offer={type="give-item", item="programmable-speaker"}} + market.add_market_item{price={{"raw-fish", 7}}, offer={type="give-item", item="programmable-speaker"}} market.add_market_item{price={{"raw-fish", 3}}, offer={type="give-item", item="piercing-rounds-magazine"}} market.add_market_item{price={{"raw-fish", 2}}, offer={type="give-item", item="grenade"}} market.add_market_item{price={{"raw-fish", 1}}, offer={type="give-item", item="land-mine"}} market.add_market_item{price={{"raw-fish", 1}}, offer={type="give-item", item="solid-fuel"}} market.add_market_item{price={{"raw-fish", 125}}, offer={type="give-item", item="rocket-launcher"}} - market.add_market_item{price={{"raw-fish", 15}}, offer={type="give-item", item="rocket"}} - market.add_market_item{price={{"raw-fish", 20}}, offer={type="give-item", item="explosive-rocket"}} - market.add_market_item{price={{"raw-fish", 2500}}, offer={type="give-item", item="atomic-bomb"}} - market.add_market_item{price={{"raw-fish", 1000}}, offer={type="give-item", item="belt-immunity-equipment"}} - -end + market.add_market_item{price={{"raw-fish", 15}}, offer={type="give-item", item="rocket"}} + market.add_market_item{price={{"raw-fish", 20}}, offer={type="give-item", item="explosive-rocket"}} + market.add_market_item{price={{"raw-fish", 2500}}, offer={type="give-item", item="atomic-bomb"}} + market.add_market_item{price={{"raw-fish", 100}}, offer={type="give-item", item="loader"}} + market.add_market_item{price={{"raw-fish", 175}}, offer={type="give-item", item="fast-loader"}} + market.add_market_item{price={{"raw-fish", 250}}, offer={type="give-item", item="express-loader"}} + market.add_market_item{price={{"raw-fish", 1000}}, offer={type="give-item", item="belt-immunity-equipment"}} -local function create_market_init_button(event) - local player = game.players[1] - - if player.gui.top.poll == nil then - local button = player.gui.top.add { name = "poll", type = "sprite-button", sprite = "item/programmable-speaker" } - button.style.font = "default-bold" - 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 end local fish_market_message = {} @@ -94,23 +93,23 @@ local function fish_earned(event, amount) local player = game.players[event.player_index] player.insert { name = "raw-fish", count = amount } - + if global.fish_market_fish_caught[event.player_index] then global.fish_market_fish_caught[event.player_index] = global.fish_market_fish_caught[event.player_index] + 1 else global.fish_market_fish_caught[event.player_index] = 1 end - + if global.fish_market_fish_caught[event.player_index] <= total_fish_market_messages then local x = global.fish_market_fish_caught[event.player_index] player.print(fish_market_message[x]) - end - + end + local x = global.fish_market_fish_caught[event.player_index] % 7 if x == 0 then local z = math.random(1,total_fish_market_bonus_messages) player.print(fish_market_bonus_message[z]) - end + end end @@ -120,49 +119,232 @@ local function preplayer_mined_item(event) -- game.print(event.entity.type) if event.entity.type == "resource" then - local x = math.random(1,2) - if x == 1 then + local x = math.random(1,2) + if x == 1 then fish_earned(event, 1) - end + end end - if event.entity.name == "fish" then - fish_earned(event, 0) + if event.entity.name == "fish" then + fish_earned(event, 0) end - - if event.entity.name == "stone-rock" then - fish_earned(event, 10) + + if event.entity.name == "stone-rock" then + fish_earned(event, 10) end - - if event.entity.name == "huge-rock" then - fish_earned(event, 25) + + if event.entity.name == "red-desert-rock-huge-01" then + fish_earned(event, 20) end - - if event.entity.name == "big-rock" then - fish_earned(event, 15) + + if event.entity.name == "red-desert-rock-big-01" then + fish_earned(event, 10) end if event.entity.type == "tree" then local x = math.random(1,4) - if x == 1 then + if x == 1 then fish_earned(event, 4) end end end local function fish_drop_entity_died(event) - + if event.entity.force.name == "enemy" then -- global.score_biter_total_kills = global.score_biter_total_kills + 1 -- game.print(global.score_biter_total_kills) - if global.score_biter_total_kills % 30 == 0 then + if global.score_biter_total_kills % 150 == 0 then local surface = event.entity.surface - local x = math.random(1,3) + local x = math.random(1,2) surface.spill_item_stack(event.entity.position, { name = "raw-fish", count = x }, 1) end - end + end end +function pet(player, entity_name) + if not player then + player = game.connected_players[1] + else + player = game.players[player] + end + if not entity_name then + entity_name = "small-biter" + end + if not global.player_pets then global.player_pets = {} end + + local surface = game.surfaces[1] + + local pos = player.position + pos.y = pos.y + 1 + + local x = 1 + x = x + #global.player_pets + + global.player_pets[x] = {} + global.player_pets[x].entity = surface.create_entity {name=entity_name, position=pos, force="player"} + global.player_pets[x].owner = player.index + global.player_pets[x].id = x + +end + +local function reset_player_runningspeed(player) + player.character_running_speed_modifier = global.player_speed_boost_records[player.index].pre_boost_modifier + global.player_speed_boost_records[player.index] = nil +end + +local function boost_player_runningspeed(player) + if global.player_speed_boost_records == nil then global.player_speed_boost_records = {} end + + if global.player_speed_boost_records[player.index] == nil then + global.player_speed_boost_records[player.index] = { + start_tick = game.tick, + pre_boost_modifier = player.character_running_speed_modifier, + boost_lvl = 0 + } + end + local boost_msg = { + [1] = "%s found the lost Dragon Scroll and got a lv.1 speed boost!", + [2] = "Guided by Master Oogway, %s got a lv.2 speed boost!", + [3] = "Kungfu Master %s defended the village and was awarded a lv.3 speed boost!", + [4] = "Travelled at the speed of light. %s saw a blackhole. Oops." + } + global.player_speed_boost_records[player.index].boost_lvl = 1 + global.player_speed_boost_records[player.index].boost_lvl + player.character_running_speed_modifier = 1 + player.character_running_speed_modifier + game.print(string.format(boost_msg[global.player_speed_boost_records[player.index].boost_lvl], player.name)) + if global.player_speed_boost_records[player.index].boost_lvl >= 4 then + reset_player_runningspeed(player) + player.character.die() + end +end + +local function market_item_purchased(event) + + local player = game.players[event.player_index] + + if event.offer_index == 1 then -- exoskeleton-equipment + player.get_inventory(defines.inventory.player_main).remove({name="exoskeleton-equipment", count=event.count}) + boost_player_runningspeed(player) + end + + if event.offer_index == 2 then + player.get_inventory(defines.inventory.player_main).remove({name="small-plane", count=event.count}) + local chance = 4 + local x = math.random(1,3) + if x < 3 then + local x = math.random(1,chance) + if x < chance then + rolled_pet = "small-biter" + else + local x = math.random(1,chance) + if x < chance then + rolled_pet = "medium-biter" + else + local x = math.random(1,chance) + if x < chance then + rolled_pet = "big-biter" + else + rolled_pet = "behemoth-biter" + end + end + end + else + local x = math.random(1,chance) + if x < chance then + rolled_pet = "small-spitter" + else + local x = math.random(1,chance) + if x < chance then + rolled_pet = "medium-spitter" + else + local x = math.random(1,chance) + if x < chance then + rolled_pet = "big-spitter" + else + rolled_pet = "behemoth-spitter" + end + end + end + end + local str = player.name + str = str .. " bought his very own pet " + str = str .. rolled_pet + str = str .. " at the fish market!!" + game.print(str) + pet(event.player_index, rolled_pet) + end + +end + +if not global.pet_command_rotation then global.pet_command_rotation = 1 end + +local function on_tick(event) + + if game.tick % 1000 == 0 then + if global.player_speed_boost_records then + for k,v in pairs(global.player_speed_boost_records) do + if game.tick - v.start_tick > 3000 then + reset_player_runningspeed(game.players[k]) + end + end + end + end + + if game.tick % 200 == 0 then + for _, pets in pairs(global.player_pets) do + local player = game.players[pets.owner] + if pcall(function () local x = pets.entity.name end) then + if global.pet_command_rotation % 15 == 0 then + local surface = game.surfaces[1] + local pet_pos = pets.entity.position + local pet_name = pets.entity.name + local pet_direction = pets.entity.direction + pets.entity.destroy() + pets.entity = surface.create_entity {name=pet_name, position=pet_pos, direction=pet_direction, force="player"} + end + if global.pet_command_rotation % 2 == 1 then + pets.entity.set_command({type=defines.command.go_to_location, destination=player.position,distraction=defines.distraction.none}) + else + local fake_pos = pets.entity.position + pets.entity.set_command({type=defines.command.go_to_location, destination=fake_pos,distraction=defines.distraction.none}) + end + else + global.player_pets[pets.id] = nil + local str = player.name .. "´s pet died ;_;" + game.print(str) + end + end + global.pet_command_rotation = global.pet_command_rotation + 1 + end +end + +function help() + local infotext = global.player_pets[1].entity.help() + player = game.players[1] + player.gui.left.direction = "horizontal" + local frame = player.gui.left.add { type = "frame", name = "info_panel"} + frame.style.top_padding = 20 + frame.style.left_padding = 20 + frame.style.right_padding = 20 + frame.style.bottom_padding = 20 + local info_table = frame.add { type = "table", colspan = 1, name = "info_table" } + local headline_label = info_table.add { type = "label", name = "headline_label", caption = "redmew fishy info" } + headline_label.style.font = "default-listbox" + headline_label.style.font_color = { r=0.98, g=0.66, b=0.22} + + + local text_box = info_table.add { type = "text-box", text = infotext, name = "text_box" } + text_box.read_only = true + text_box.selectable = true + text_box.word_wrap = false + text_box.style.right_padding = 5 + text_box.style.top_padding = 5 + text_box.style.left_padding = 5 + text_box.style.bottom_padding = 5 +end + Event.register(defines.events.on_preplayer_mined_item, preplayer_mined_item) Event.register(defines.events.on_entity_died, fish_drop_entity_died) +Event.register(defines.events.on_market_item_purchased, market_item_purchased) +Event.register(defines.events.on_tick, on_tick) diff --git a/info.lua b/info.lua index 220d47ff..3b8acd68 100644 --- a/info.lua +++ b/info.lua @@ -1,7 +1,7 @@ local function create_info_button(event) local player = game.players[event.player_index] - if player.gui.top.info == nil then + if player.gui.top.info_button == nil then local button = player.gui.top.add({ type = "sprite-button", name = "info_button", sprite = "item/raw-fish" }) button.style.minimal_height = 38 button.style.minimal_width = 38 diff --git a/map_layout.lua b/map_layout.lua index d3c8ee94..1b98306a 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -1,74 +1,1368 @@ -if not global.map_layout_name then global.map_layout_name = "" end +--[[ +Hey there! -local islandWidth = 512 -local islandHeight = 512 -local distanceToContinent = 10000 -local pathHeight = 32 +With this you can customize your world generation. +Just set the map_styles of your choice to true to make it happen. -local function removeChunk(event) - local tiles = {} - for x = event.area.left_top.x, event.area.right_bottom.x do - for y = event.area.left_top.y, event.area.right_bottom.y do - table.insert(tiles, {name = "out-of-map", position = {x,y}}) - end - end - event.surface.set_tiles(tiles) +---MewMew--- + +notes: + +--]] + +require "perlin_noise" +perlin:load( ) +if not global.perlin_noise_seed then global.perlin_noise_seed = math.random(1000,1000000) end + +local map_styles = {} + +map_styles = { +up = false, +right = false, +square = false, +circle = false, +red_planet = false, +dagobah_swamp = false, +grey_void = false, +resource_cluster_truck = false, +perlin_01 = false, +perlin_02 = false +} + +if map_styles.red_planet == true or map_styles.dagobah_swamp == true then + wreck_item_pool = {} + wreck_item_pool = {{name="iron-gear-wheel", count=32},{name="iron-plate", count=64},{name="rocket-control-unit", count=1} ,{name="coal", count=4},{name="rocket-launcher", count=1},{name="rocket", count=32},{name="copper-cable", count=128},{name="land-mine", count=64},{name="railgun", count=1},{name="railgun-dart", count=128},{name="fast-inserter", count=8},{name="stack-filter-inserter", count=2},{name="belt-immunity-equipment", count=1},{name="fusion-reactor-equipment", count=1},{name="electric-engine-unit", count=8},{name="exoskeleton-equipment", count=1},{name="rocket-fuel", count=10},{name="used-up-uranium-fuel-cell", count=3},{name="uranium-fuel-cell", count=2}} end -local function generateIslandChunk(event) - -end - -local function generatePathChunk(event) - local tiles = {} - for x = event.area.left_top.x, event.area.right_bottom.x do - for y = event.area.left_top.y, event.area.right_bottom.y do - table.insert(tiles, {name = "grass", position = {x,y}}) - end - end - event.surface.set_tiles(tiles) -end - -local function chunk_modification(event) - if global.map_layout_name == "Up" then - if event.area.left_top.y > 50 or event.area.left_top.x > 96 or event.area.left_top.x < -128 then - removeChunk(event) - end - end - - - if global.map_layout_name == "HolyLand" then - local x = event.area.left_top.x - local y = event.area.left_top.y - if x < distanceToContinent then - if x >= (islandWidth/(-2)) then - -- - if (x < (islandWidth/2)) and (math.abs(y) <= (islandHeight/2)) then - generateIslandChunk(event) - elseif (math.abs(y) <= pathHeight/2) and x >= islandWidth/2 then - generatePathChunk(event) - else - removeChunk(event) +local function place_entities(surface, entity_list) + local directions = {defines.direction.north, defines.direction.east, defines.direction.south, defines.direction.west} + for _, entity in pairs(entity_list) do + local r = math.random(1,entity.chance) + if r == 1 then + if not entity.force then entity.force = "player" end + local r = math.random(1,4) + if surface.can_place_entity {name=entity.name, position=entity.pos, direction=directions[r], force=entity.force} then + local e = surface.create_entity {name=entity.name, position=entity.pos, direction=directions[r], force=entity.force} + if entity.health then + if entity.health == "low" then e.health = ((e.health / 1000) * math.random(33,330)) end + if entity.health == "medium" then e.health = ((e.health / 1000) * math.random(333,666)) end + if entity.health == "high" then e.health = ((e.health / 1000) * math.random(666,999)) end + if entity.health == "random" then e.health = ((e.health / 1000) * math.random(1,1000)) end end - else - removeChunk(event) - end - + return true, e + end + end + end + return false +end + +local function auto_place_entity_around_target(entity, scan_radius, mode, density, surface) + local x = entity.pos.x + local y = entity.pos.y + if not surface then surface = game.surfaces[1] end + if not scan_radius then scan_radius = 6 end + if not entity then return end + if not mode then mode = "ball" end + if not density then density = 1 end + + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + + local i = 2 + local r = 1 + + if mode == "ball" then + if math.random(1,2) == 1 then + density = density * -1 end - end -end - -local function removeResourcesFromArea(cArea) - for _,v in pairs(game.surfaces.nauvis.find_entities_filtered{area=cArea}) do - v.destroy() + r = math.random(1,4) end -end - -local function on_tick(event) - if (event.tick % 300) == 0 then - removeResourcesFromArea({left_top = {islandWidth/2, 0}, right_bottom = {islandWidth/2 + distanceToContinent, pathHeight}}) + if mode == "line" then + density = 1 + r = math.random(1,4) end + if mode == "line_down" then + density = density * -1 + r = math.random(1,4) + end + if mode == "line_up" then + density = 1 + r = math.random(1,4) + end + if mode == "block" then + r = 1 + density = 1 + end + + if r == 1 then + --start placing at -1,-1 + while i <= scan_radius do + y = y - density + x = x - density + for a = 1, i, 1 do + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + x = x + density + end + for a = 1, i, 1 do + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + y = y + density + end + for a = 1, i, 1 do + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + x = x - density + end + for a = 1, i, 1 do + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + y = y - density + end + i = i + 2 + end + end + + if r == 2 then + --start placing at 0,-1 + while i <= scan_radius do + y = y - density + x = x - density + for a = 1, i, 1 do + x = x + density + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + end + for a = 1, i, 1 do + y = y + density + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + end + for a = 1, i, 1 do + x = x - density + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + end + for a = 1, i, 1 do + y = y - density + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + end + i = i + 2 + end + end + + if r == 3 then + --start placing at 1,-1 + while i <= scan_radius do + y = y - density + x = x + density + for a = 1, i, 1 do + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + y = y + density + end + for a = 1, i, 1 do + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + x = x - density + end + for a = 1, i, 1 do + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + y = y - density + end + for a = 1, i, 1 do + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + x = x + density + end + i = i + 2 + end + end + + if r == 4 then + --start placing at 1,0 + while i <= scan_radius do + y = y - density + x = x + density + for a = 1, i, 1 do + y = y + density + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + end + for a = 1, i, 1 do + x = x - density + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + end + for a = 1, i, 1 do + y = y - density + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + end + for a = 1, i, 1 do + x = x + density + if surface.can_place_entity {name=entity.name, position={x,y}} then + local e = surface.create_entity {name=entity.name, position={x,y}} + return true, e + end + end + i = i + 2 + end + end + + return false end -Event.register(defines.events.on_chunk_generated, chunk_modification) -Event.register(defines.events.on_tick, on_tick) \ No newline at end of file +local function create_entitie_cluster(name, pos, amount) + + local surface = game.surfaces[1] + local entity = {} + entity.pos = pos + entity.name = name + local mode = "ball" + + for i = 1, amount, 1 do + local b, e = auto_place_entity_around_target(entity, 30, mode) + if b == true then + if 1 == math.random(1,40) then + entity.pos = e.position + end + if e.type == "resource" then + e.amount = math.random(500,1500) + end + end + end + return b, e +end + +local function create_rock_cluster(pos, amount) + if not pos then return false end + if amount == nil then amount = 7 end + local scan_radius = amount * 2 + local mode = "line_down" + if math.random(1,2) == 1 then mode = "line_up" end + local entity = {} + entity.pos = pos + for i = 1, amount, 1 do + if 1 == math.random(1,3) then + entity.name = "red-desert-rock-huge-01" + else + entity.name = "red-desert-rock-big-01" + end + local b, e = auto_place_entity_around_target(entity, scan_radius, mode) + if b == true then + if 1 ~= math.random(1,20) then + entity.pos = e.position + end + end + end + return b, e +end + +local function create_tree_cluster(pos, amount) + if not pos then return false end + if amount == nil then amount = 7 end + local scan_radius = amount * 2 + --local mode = "line_down" + --if math.random(1,2) == 1 then mode = "line_up" end + local mode = "ball" + local entity = {} + entity.pos = pos + for i = 1, amount, 1 do + entity.name = "tree-06" + local density = 2 + if 1 == math.random(1,20) then entity.name = "tree-07" end + if 1 == math.random(1,70) then entity.name = "tree-09" end + if 1 == math.random(1,10) then entity.name = "tree-04" end + if 1 == math.random(1,9) then density = 1 end + if 1 == math.random(1,3) then density = 3 end + if 1 == math.random(1,3) then density = 4 end + + local b, e = auto_place_entity_around_target(entity, scan_radius, mode, density) + if b == true then + if 1 == math.random(1,3) then + entity.pos = e.position + end + end + end + return b, e +end + +local function find_tile_placement_spot_around_target_position(tilename, position, mode, density) + local x = position.x + local y = position.y + if not surface then surface = game.surfaces[1] end + local scan_radius = 50 + if not tilename then return end + if not mode then mode = "ball" end + if not density then density = 1 end + local cluster_tiles = {} + local auto_correct = false + + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,false) + return true, x, y + end + + local i = 2 + local r = 1 + + if mode == "ball" then + if math.random(1,2) == 1 then + density = density * -1 + end + r = math.random(1,4) + end + if mode == "line" then + density = 1 + r = math.random(1,4) + end + if mode == "line_down" then + density = density * -1 + r = math.random(1,4) + end + if mode == "line_up" then + density = 1 + r = math.random(1,4) + end + if mode == "block" then + r = 1 + density = 1 + end + + if r == 1 then + --start placing at -1,-1 + while i <= scan_radius do + y = y - density + x = x - density + for a = 1, i, 1 do + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + x = x + density + end + for a = 1, i, 1 do + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + y = y + density + end + for a = 1, i, 1 do + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + x = x - density + end + for a = 1, i, 1 do + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + y = y - density + end + i = i + 2 + end + end + + if r == 2 then + --start placing at 0,-1 + while i <= scan_radius do + y = y - density + x = x - density + for a = 1, i, 1 do + x = x + density + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + end + for a = 1, i, 1 do + y = y + density + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + end + for a = 1, i, 1 do + x = x - density + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + end + for a = 1, i, 1 do + y = y - density + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + end + i = i + 2 + end + end + + if r == 3 then + --start placing at 1,-1 + while i <= scan_radius do + y = y - density + x = x + density + for a = 1, i, 1 do + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + y = y + density + end + for a = 1, i, 1 do + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + x = x - density + end + for a = 1, i, 1 do + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + y = y - density + end + for a = 1, i, 1 do + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + x = x + density + end + i = i + 2 + end + end + + if r == 4 then + --start placing at 1,0 + while i <= scan_radius do + y = y - density + x = x + density + for a = 1, i, 1 do + y = y + density + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + end + for a = 1, i, 1 do + x = x - density + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + end + for a = 1, i, 1 do + y = y - density + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + end + for a = 1, i, 1 do + x = x + density + local scanned_tile = surface.get_tile(x,y) + if scanned_tile.name ~= tilename then + table.insert(cluster_tiles, {name = tilename, position = {x,y}}) + surface.set_tiles(cluster_tiles,auto_correct) + return true, x, y + end + end + i = i + 2 + end + end + return false +end + +local function create_tile_cluster(tilename,position,amount) + local mode = "ball" + local cluster_tiles = {} + local surface = game.surfaces[1] + local pos = position + local x = pos.x + local y = pos.y + for i = 1, amount, 1 do + local b,x,y = find_tile_placement_spot_around_target_position(tilename, pos, mode) + if b == true then + if 1 == math.random(1,2) then + pos.x = x + pos.y = y + end + end + if b == false then return false,x,y end + if i >= amount then return true,x,y end + end +end + +local function on_chunk_generated(event) + + if map_styles.perlin_02 == true then + local seed = global.perlin_noise_seed + local surface = game.surfaces[1] + local tiles = {} + local void_tiles = {} + local entities = surface.find_entities(event.area) + for _, entity in pairs(entities) do + if entity.type ~= "player" then + entity.destroy() + end + end + + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + table.insert(void_tiles, {name = "concrete", position = {pos_x,pos_y}}) + local tile = surface.get_tile(pos_x,pos_y) + local tile_to_insert = "concrete" + + --if tile.name ~= "water" and tile.name ~= "deepwater" then + local noise_terrain_1 = perlin:noise(((pos_x+seed)/500),((pos_y+seed)/500),0) + noise_terrain_1 = noise_terrain_1 * 100 + local noise_terrain_2 = perlin:noise(((pos_x+seed+40000)/250),((pos_y+seed+40000)/250),0) + noise_terrain_2 = noise_terrain_2 * 50 + local noise_terrain_3 = perlin:noise(((pos_x+seed+50000)/50),((pos_y+seed+50000)/50),0) + noise_terrain_3 = noise_terrain_3 * 50 + local noise_terrain_4 = perlin:noise(((pos_x+seed+50000)/20),((pos_y+seed+70000)/20),0) + noise_terrain_4 = noise_terrain_4 * 10 + local noise_terrain_5 = perlin:noise(((pos_x+seed+50000)/5),((pos_y+seed+70000)/5),0) + noise_terrain_5 = noise_terrain_5 * 10 + local noise_red_desert_rocks = perlin:noise(((pos_x+seed+100000)/10),((pos_y+seed+100000)/10),0) + noise_red_desert_rocks = noise_red_desert_rocks * 100 + local p3 = perlin:noise(((pos_x+seed+200000)/10),((pos_y+seed+200000)/10),0) + p3 = p3 * 100 + local noise_forest = perlin:noise(((pos_x+seed+300000)/100),((pos_y+seed+300000)/100),0) + noise_forest = noise_forest * 100 + + local terrain_smoothing = math.random(0,1) + + if noise_terrain_1 < 8 + terrain_smoothing + noise_terrain_2 + noise_terrain_3 + noise_terrain_4 then + tile_to_insert = "red-desert" + + if noise_terrain_1 < -75 + noise_terrain_2 + noise_terrain_5 then + tile_to_insert = "water" + local a = pos_x + 1 + table.insert(tiles, {name = tile_to_insert, position = {a,pos_y}}) + local a = pos_y + 1 + table.insert(tiles, {name = tile_to_insert, position = {pos_x,a}}) + local a = pos_x - 1 + table.insert(tiles, {name = tile_to_insert, position = {a,pos_y}}) + local a = pos_y - 1 + table.insert(tiles, {name = tile_to_insert, position = {pos_x,a}}) + end + + if noise_terrain_1 < -5 then + if noise_forest > 0 and noise_forest <= 10 then + if math.random(1,50) == 1 then + if surface.can_place_entity {name="dry-tree", position={pos_x,pos_y}} then + surface.create_entity {name="dry-tree", position={pos_x,pos_y}} + end + end + end + if noise_forest > 10 and noise_forest <= 20 then + if math.random(1,25) == 1 then + if surface.can_place_entity {name="dry-tree", position={pos_x,pos_y}} then + surface.create_entity {name="dry-tree", position={pos_x,pos_y}} + end + end + end + if noise_forest > 20 then + if math.random(1,10) == 1 then + if surface.can_place_entity {name="dry-tree", position={pos_x,pos_y}} then + surface.create_entity {name="dry-tree", position={pos_x,pos_y}} + end + end + end + end + else + tile_to_insert = "red-desert-dark" + + if noise_red_desert_rocks > 20 and noise_terrain_1 > -2 + terrain_smoothing + noise_terrain_2 + noise_terrain_3 then + if math.random(1,3) == 1 then + if surface.can_place_entity {name="red-desert-rock-huge-01", position={pos_x,pos_y}} then + surface.create_entity {name="red-desert-rock-huge-01", position={pos_x,pos_y}} + end + else + if surface.can_place_entity {name="red-desert-rock-big-01", position={pos_x,pos_y}} then + surface.create_entity {name="red-desert-rock-big-01", position={pos_x,pos_y}} + end + end + end + end + --else + -- if tile.name == "water" then tile_to_insert = "water" end + -- if tile.name == "deepwater" then tile_to_insert = "deepwater" end + --end + table.insert(tiles, {name = tile_to_insert, position = {pos_x,pos_y}}) + end + end + --surface.set_tiles(void_tiles,false) + surface.set_tiles(tiles,true) + --surface.set_tiles(tiles,true) + + end + + if map_styles.perlin_01 == true then + local seed = global.perlin_noise_seed + local tiles = {} + local entities = event.surface.find_entities(event.area) + for _, entity in pairs(entities) do + if entity.type ~= "player" then + entity.destroy() + end + end + local entity_list = {} + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + local p = perlin:noise(((pos_x+seed)/10),((pos_y+seed)/10),0) + p = round((p * 100),0) + 50 + if p < 55 then table.insert(tiles, {name = "concrete", position = {pos_x,pos_y}}) end + if p >= 55 then table.insert(tiles, {name = "stone-path", position = {pos_x,pos_y}}) end + if p >= 56 and p <= 80 then + if event.surface.can_place_entity {name="stone-wall", position={pos_x,pos_y}} then + event.surface.create_entity {name="stone-wall", position={pos_x,pos_y}} + end + end + if p >= 99 and p < 100 then + if event.surface.can_place_entity {name="accumulator", position={pos_x,pos_y}} then + event.surface.create_entity {name="accumulator", position={pos_x,pos_y}} + end + end + if p >= 102 and p < 105 then + if event.surface.can_place_entity {name="substation", position={pos_x,pos_y}} then + event.surface.create_entity {name="substation", position={pos_x,pos_y}} + end + end + if p >= 105 and p < 111 then + if event.surface.can_place_entity {name="solar-panel", position={pos_x,pos_y}} then + event.surface.create_entity {name="solar-panel", position={pos_x,pos_y}} + end + end + if p >= 111 then + if event.surface.can_place_entity {name="laser-turret", position={pos_x,pos_y}} then + event.surface.create_entity {name="laser-turret", position={pos_x,pos_y}} + end + end + end + end + event.surface.set_tiles(tiles,true) + end + + if map_styles.square == true then + local size = 30 + size = size / 2 + size = round(size,0) + local negative_size = size * -1 + local area = event.area + local surface = event.surface + local tiles = {} + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + if pos_y >= size or pos_x >= size or pos_x < negative_size or pos_y < negative_size then + table.insert(tiles, {name = "out-of-map", position = {pos_x,pos_y}}) + end + end + end + surface.set_tiles(tiles) + end + + if map_styles.circle == true then + local radius = 1609 + local radsquare = radius*radius + local surface = event.surface + local tiles = {} + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local tile_distance_to_center = nil + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + local a = pos_y * pos_y + local b = pos_x * pos_x + local tile_distance_to_center = a + b + if tile_distance_to_center >= radsquare then + table.insert(tiles, {name = "out-of-map", position = {pos_x,pos_y}}) + end + end + end + surface.set_tiles(tiles) + end + + if map_styles.resource_cluster_truck == true then + if not global.resource_cluster_truck then global.resource_cluster_truck = 1 end + local entities = event.surface.find_entities(event.area) + for _, entity in pairs(entities) do + if entity.type == "resource" then + entity.destroy() + end + end + local pos_x = event.area.left_top.x + math.random(10, 20) + local pos_y = event.area.left_top.y + math.random(10, 20) + local radius = 10 + local surface = event.surface + local tiles = {} + local center = 15 + local ore_spawn = math.random(1,6) + local oil_amount = math.random(10000,150000) + local resource_amount = math.random(400,7000) + if math.random(1,12) == 1 then resource_amount = math.random(7000,150000) end + if global.resource_cluster_truck % 2 == 1 then + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local tile_distance_to_center = nil + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + center_x = event.area.left_top.x + center + center_y = event.area.left_top.y + center + local a = (pos_x - center_x) * (pos_x - center_x) + local b = (pos_y - center_y) * (pos_y - center_y) + local tile_distance_to_center = math.sqrt(a + b) + if tile_distance_to_center < radius then + + if tile_distance_to_center <= 0 then tile_distance_to_center = tile_distance_to_center * -1 end + tile_distance_to_center = tile_distance_to_center + 1 + + local amount = resource_amount + if tile_distance_to_center < radius / 2 then + amount = resource_amount * 1.5 + end + if tile_distance_to_center < radius / 3 then + amount = resource_amount * 2 + end + + if ore_spawn == 6 then amount = oil_amount end + + if ore_spawn == 1 then + if surface.can_place_entity {name="stone", position={x=pos_x,y=pos_y}, amount = amount} then + surface.create_entity {name="stone", position={x=pos_x,y=pos_y}, amount = amount} + end + end + if ore_spawn == 2 then + if surface.can_place_entity {name="iron-ore", position={x=pos_x,y=pos_y}, amount = amount} then + surface.create_entity {name="iron-ore", position={x=pos_x,y=pos_y}, amount = amount} + end + end + if ore_spawn == 3 then + if surface.can_place_entity {name="coal", position={x=pos_x,y=pos_y}, amount = amount} then + surface.create_entity {name="coal", position={x=pos_x,y=pos_y}, amount = amount} + end + end + if ore_spawn == 4 then + if surface.can_place_entity {name="copper-ore", position={x=pos_x,y=pos_y}, amount = amount} then + surface.create_entity {name="copper-ore", position={x=pos_x,y=pos_y}, amount = amount} + end + end + if ore_spawn == 5 then + if surface.can_place_entity {name="uranium-ore", position={x=pos_x,y=pos_y}, amount = amount} then + surface.create_entity {name="uranium-ore", position={x=pos_x,y=pos_y}, amount = amount} + end + end + if ore_spawn == 6 then + if surface.can_place_entity {name="crude-oil", position={x=pos_x,y=pos_y}, amount = amount} then + surface.create_entity {name="crude-oil", position={x=pos_x,y=pos_y}, amount = amount} + end + end + end + end + end + end + global.resource_cluster_truck = global.resource_cluster_truck + 1 + end + + if map_styles.up == true then + local area = event.area + local surface = event.surface + local tiles = {} + if event.area.left_top.y > 50 or event.area.left_top.x > 96 or event.area.left_top.x < -128 then + for x = event.area.left_top.x, event.area.right_bottom.x do + for y = event.area.left_top.y, event.area.right_bottom.y do + table.insert(tiles, {name = "out-of-map", position = {x,y}}) + end + end + surface.set_tiles(tiles) + end + end + + if map_styles.right == true then + local area = event.area + local surface = event.surface + local tiles = {} + if event.area.left_top.x < -75 or event.area.left_top.y > 32 or event.area.left_top.y < -400 then + for x = event.area.left_top.x, event.area.right_bottom.x do + for y = event.area.left_top.y, event.area.right_bottom.y do + table.insert(tiles, {name = "out-of-map", position = {x,y}}) + end + end + surface.set_tiles(tiles) + end + end + + if map_styles.dagobah_swamp == true then + local area = event.area + local surface = event.surface + --local surface = game.surfaces[1] + local tiles = {} + local decoratives = {} + + local entities = surface.find_entities(area) + for _, entity in pairs(entities) do + if entity.type == "simple-entity" or entity.type == "tree" then + if entity.name ~= "tree-09" and entity.name ~= "tree-07" and entity.name ~= "tree-06" then --and entity.name ~= "tree-04" + entity.destroy() + end + end + end + local forest_cluster = true + if math.random(1,4) == 1 then forest_cluster = false end + + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + local pos = {x = pos_x,y = pos_y} + local tile = surface.get_tile(pos_x,pos_y) + local tile_to_insert = tile + local entity_placed = false + -- or tile.name == "grass-dry" + if tile.name ~= "water" and tile.name ~= "deepwater" then + tile_to_insert = "grass" + + local entity_list = {} + table.insert(entity_list, {name="big-ship-wreck-1", pos={pos_x,pos_y},chance = 65000, health="random"}) + table.insert(entity_list, {name="big-ship-wreck-2", pos={pos_x,pos_y},chance = 65000, health="random"}) + table.insert(entity_list, {name="big-ship-wreck-3", pos={pos_x,pos_y},chance = 65000, health="random"}) + local b, placed_entity = place_entities(surface, entity_list) + if b == true then + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + end + + local entity_list = {} + table.insert(entity_list, {name="tree-04", pos={pos_x,pos_y},chance = 400}) + table.insert(entity_list, {name="tree-09", pos={pos_x,pos_y},chance = 1000}) + table.insert(entity_list, {name="tree-07", pos={pos_x,pos_y},chance = 400}) + table.insert(entity_list, {name="tree-06", pos={pos_x,pos_y},chance = 150}) + table.insert(entity_list, {name="stone-rock", pos={pos_x,pos_y},chance = 400}) + table.insert(entity_list, {name="green-coral", pos={pos_x,pos_y},chance = 10000}) + table.insert(entity_list, {name="medium-ship-wreck", pos={pos_x,pos_y},chance = 25000, health="random"}) + table.insert(entity_list, {name="small-ship-wreck", pos={pos_x,pos_y},chance = 25000, health="random"}) + table.insert(entity_list, {name="car", pos={pos_x,pos_y},chance = 125000, health="low"}) + table.insert(entity_list, {name="stone-furnace", pos={pos_x,pos_y},chance = 100000, health="random", force="enemy"}) + local b, placed_entity = place_entities(surface, entity_list) + + if forest_cluster == true then + if math.random(1,800) == 1 then create_tree_cluster(pos, 120) end + end + + else + if tile.name == "water" then tile_to_insert = "water" end + if tile.name == "deepwater" then tile_to_insert = "deepwater" end + end + table.insert(tiles, {name = tile_to_insert, position = {pos_x,pos_y}}) + end + end + surface.set_tiles(tiles,true) + + --check for existing chunk if you would overwrite decoratives + local for_start_x = 0 + local for_end_x = 31 + local for_start_y = 0 + local for_end_y = 31 + local testing_pos = event.area.left_top.x - 1 + local tile = surface.get_tile(testing_pos, event.area.left_top.y) + if tile.name then for_start_x = -1 end + local testing_pos = event.area.left_top.y - 1 + local tile = surface.get_tile(event.area.left_top.x, testing_pos) + if tile.name then for_start_y = -1 end + local testing_pos = event.area.right_bottom.x + local tile = surface.get_tile(testing_pos, event.area.right_bottom.y) + if tile.name then for_end_x = 32 end + local testing_pos = event.area.right_bottom.y + local tile = surface.get_tile(event.area.right_bottom.x, testing_pos) + if tile.name then for_end_y = 32 end + + for x = for_start_x, for_end_x, 1 do + for y = for_start_y, for_end_y, 1 do + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + local tile = surface.get_tile(pos_x, pos_y) + local decal_has_been_placed = false + + if tile.name == "grass" then + if decal_has_been_placed == false then + local r = math.random(1,3) + if r == 1 then + table.insert(decoratives, {name="green-carpet-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + if decal_has_been_placed == false then + local r = math.random(1,7) + if r == 1 then + table.insert(decoratives, {name="green-hairy-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + if decal_has_been_placed == false then + local r = math.random(1,10) + if r == 1 then + table.insert(decoratives, {name="green-bush-mini", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + if decal_has_been_placed == false then + local r = math.random(1,6) + if r == 1 then + table.insert(decoratives, {name="green-pita", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + if decal_has_been_placed == false then + local r = math.random(1,12) + if r == 1 then + table.insert(decoratives, {name="green-small-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + if decal_has_been_placed == false then + local r = math.random(1,25) + if r == 1 then + table.insert(decoratives, {name="green-asterisk", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + end + if tile.name == "water" then + + if decal_has_been_placed == false then + local r = math.random(1,18) + if r == 1 then + table.insert(decoratives, {name="green-carpet-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + if decal_has_been_placed == false then + local r = math.random(1,950) + if r == 1 then + table.insert(decoratives, {name="green-small-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + if decal_has_been_placed == false then + local r = math.random(1,150) + if r == 1 then + table.insert(decoratives, {name="green-bush-mini", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = false + end + end + end + end + end + for _,deco in pairs(decoratives) do + surface.create_decoratives{check_collision=false, decoratives={deco}} + end + end + + if map_styles.red_planet == true then + local area = event.area + local surface = event.surface + local tiles = {} + local water_tiles = {} + local decoratives = {} + + local entities = surface.find_entities(area) + for _, entity in pairs(entities) do + if entity.type == "tree" or entity.type == "simple-entity" then + entity.destroy() + end + end + local rock_cluster = true + if math.random(1,3) == 1 then rock_cluster = false end + + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + local pos = {pos_x,pos_y} + local tile = surface.get_tile(pos_x,pos_y) + local entity_placed = false + -- or tile.name == "grass-dry" + if tile.name == "grass" or tile.name == "sand" or tile.name == "dirt" or tile.name == "grass-medium" then + table.insert(tiles, {name = "red-desert", position = {pos_x,pos_y}}) + local entity_list = {} + table.insert(entity_list, {name="dry-tree", pos={pos_x,pos_y},chance = 160}) + table.insert(entity_list, {name="red-desert-rock-big-01", pos={pos_x,pos_y},chance = 800}) + table.insert(entity_list, {name="red-desert-rock-huge-01", pos={pos_x,pos_y},chance = 1500}) + table.insert(entity_list, {name="stone-rock", pos={pos_x,pos_y},chance = 1300}) + table.insert(entity_list, {name="medium-ship-wreck", pos={pos_x,pos_y},chance = 15000, health="medium"}) + table.insert(entity_list, {name="small-ship-wreck", pos={pos_x,pos_y},chance = 15000, health="medium"}) + table.insert(entity_list, {name="car", pos={pos_x,pos_y},chance = 100000, health="low"}) + table.insert(entity_list, {name="nuclear-reactor", pos={pos_x,pos_y},chance = 1000000, force="enemy", health="medium"}) + local b, placed_entity = place_entities(surface, entity_list) + if b == false then + table.insert(entity_list, {name="big-ship-wreck-1", pos={pos_x,pos_y},chance = 75000, health="random"}) + table.insert(entity_list, {name="big-ship-wreck-2", pos={pos_x,pos_y},chance = 75000, health="random"}) + table.insert(entity_list, {name="big-ship-wreck-3", pos={pos_x,pos_y},chance = 75000, health="random"}) + local b, placed_entity = place_entities(surface, entity_list) + if b == true then + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + end + end + else + if tile.name == "water" or tile.name == "water-green" then + --table.insert(water_tiles, {name = "water-green", position = {pos_x,pos_y}}) + else + if tile.name == "deepwater" or tile.name == "deepwater-green" then + --table.insert(water_tiles, {name = "deepwater-green", position = {pos_x,pos_y}}) + else + table.insert(tiles, {name = "red-desert-dark", position = {pos_x,pos_y}}) + if rock_cluster == true then + if math.random(1,1200) == 1 then create_rock_cluster({x=pos_x,y=pos_y},math.random(15,75)) end + end + local entity_list = {} + table.insert(entity_list, {name="red-desert-rock-big-01", pos={pos_x,pos_y},chance = 400}) + table.insert(entity_list, {name="red-desert-rock-huge-01", pos={pos_x,pos_y},chance = 700}) + table.insert(entity_list, {name="pipe-to-ground", pos={pos_x,pos_y},chance = 15000, force="enemy"}) + table.insert(entity_list, {name="programmable-speaker", pos={pos_x,pos_y},chance = 25000, force="enemy", health="high"}) + table.insert(entity_list, {name="laser-turret", pos={pos_x,pos_y},chance = 50000, force="enemy", health="low"}) + table.insert(entity_list, {name="tank", pos={pos_x,pos_y},chance = 500000, health="low"}) + local b, placed_entity = place_entities(surface, entity_list) + if b == false then + table.insert(entity_list, {name="big-ship-wreck-1", pos={pos_x,pos_y},chance = 75000, health="random"}) + table.insert(entity_list, {name="big-ship-wreck-2", pos={pos_x,pos_y},chance = 75000, health="random"}) + table.insert(entity_list, {name="big-ship-wreck-3", pos={pos_x,pos_y},chance = 75000, health="random"}) + local b, placed_entity = place_entities(surface, entity_list) + if b == true then + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + placed_entity.insert(wreck_item_pool[math.random(1,#wreck_item_pool)]) + end + end + end + end + end + + end + end + surface.set_tiles(tiles,true) + --surface.set_tiles(water_tiles,false) + --surface.set_tiles(water_tiles,false) + + --check for existing chunk if you would overwrite decoratives + local for_start_x = 0 + local for_end_x = 31 + local for_start_y = 0 + local for_end_y = 31 + local testing_pos = event.area.left_top.x - 1 + local tile = surface.get_tile(testing_pos, event.area.left_top.y) + if tile.name then for_start_x = -1 end + local testing_pos = event.area.left_top.y - 1 + local tile = surface.get_tile(event.area.left_top.x, testing_pos) + if tile.name then for_start_y = -1 end + local testing_pos = event.area.right_bottom.x + local tile = surface.get_tile(testing_pos, event.area.right_bottom.y) + if tile.name then for_end_x = 32 end + local testing_pos = event.area.right_bottom.y + local tile = surface.get_tile(event.area.right_bottom.x, testing_pos) + if tile.name then for_end_y = 32 end + + for x = for_start_x, for_end_x, 1 do + for y = for_start_y, for_end_y, 1 do + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + local tile = surface.get_tile(pos_x, pos_y) + local decal_has_been_placed = false + if tile.name == "red-desert" then + if decal_has_been_placed == false then + local r = math.random(1,21) + if r == 1 then + table.insert(decoratives, {name="red-desert-bush", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,34) + if r == 1 then + table.insert(decoratives, {name="red-desert-rock-tiny", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,76) + if r == 1 then + table.insert(decoratives, {name="red-desert-rock-medium", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,25) + if r == 1 then + table.insert(decoratives, {name="red-asterisk", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,36) + if r == 1 then + table.insert(decoratives, {name="brown-hairy-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,44) + if r == 1 then + table.insert(decoratives, {name="brown-carpet-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,227) + if r == 1 then + table.insert(decoratives, {name="brown-coral-mini", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,227) + if r == 1 then + table.insert(decoratives, {name="orange-coral-mini", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + + end + if tile.name == "red-desert-dark" then + if decal_has_been_placed == false then + local r = math.random(1,25) + if r == 1 then + table.insert(decoratives, {name="red-desert-bush", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,25) + if r == 1 then + table.insert(decoratives, {name="red-desert-rock-medium", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,15) + if r == 1 then + table.insert(decoratives, {name="red-desert-rock-small", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,12) + if r == 1 then + table.insert(decoratives, {name="red-desert-rock-tiny", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,27) + if r == 1 then + table.insert(decoratives, {name="red-asterisk", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,32) + if r == 1 then + table.insert(decoratives, {name="brown-hairy-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + if decal_has_been_placed == false then + local r = math.random(1,61) + if r == 1 then + table.insert(decoratives, {name="brown-carpet-grass", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + --[[if decal_has_been_placed == false then + local r = math.random(1,71) + if r == 1 then + table.insert(decoratives, {name="brown-cane-cluster", position={pos_x,pos_y}, amount=1}) + decal_has_been_placed = true + end + end + --]] + end + --[[if tile.name == "grass" then + end + if tile.name == "grass-dry" then + end + if tile.name == "grass-medium" then + end + if tile.name == "dirt" then + end + if tile.name == "dirt-dark" then + end--]] + end + end + for _,deco in pairs(decoratives) do + surface.create_decoratives{check_collision=false, decoratives={deco}} + end + end + + if map_styles.grey_void == true then + if not global.void_slime then global.void_slime = {x=0,y=0} end + if not global.void_slime_is_alive then global.void_slime_is_alive = true end + local area = event.area + local surface = event.surface + local tiles = {} + local decoratives = {} + local resource_tiles = {} + local special_tiles = true + + local entities = surface.find_entities(area) + for _, entity in pairs(entities) do + if entity.type == "resource" then + table.insert(resource_tiles, {name = "concrete", position = entity.position}) + special_tiles = false + end + if entity.type == "simple-entity" or entity.type == "tree" then + if entity.name ~= "dry-tree" then + entity.destroy() + end + end + end + + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local pos_x = event.area.left_top.x + x + local pos_y = event.area.left_top.y + y + local pos = {x = pos_x,y = pos_y} + local tile = surface.get_tile(pos_x,pos_y) + local tile_to_insert = tile + local entity_placed = false + if tile.name ~= "lab-dark-1" then + table.insert(tiles, {name = "lab-dark-1", position = {pos_x,pos_y}}) + end + end + end + surface.set_tiles(tiles,false) + surface.set_tiles(resource_tiles,false) + + if special_tiles == true then + local pos_x = event.area.left_top.x + math.random(10,21) + local pos_y = event.area.left_top.y + math.random(10,21) + local pos = {x = pos_x,y = pos_y} + if math.random(1,20) == 1 then create_tile_cluster("water", pos, 300) end + --if math.random(1,3) == 1 then create_tile_cluster("lab-dark-2", pos, 1000) end + --if math.random(1,700) == 1 then create_tile_cluster("lab-dark-2", pos, 300) end + end + end +end + +local function on_tick() + if map_styles.grey_void == true then + if game.tick % 60 == 0 then + if global.void_slime_is_alive == true then + local b,x,y = create_tile_cluster("lab-dark-2",global.void_slime,1) + global.void_slime.x = x + global.void_slime.y = y + if b == false then + global.void_slime_is_alive = false + game.print("The void slime died.") + end + end + end + end +end +--[[ +function regen() + game.surfaces[1].regenerate_decorative {"red-asterisk", "green-bush-mini", "green-carpet-grass" } +end + +function reveal(var) + local a = var + local b = var * -1 + game.forces.player.chart(game.player.surface, {lefttop = {x = a, y = a}, rightbottom = {x = b, y = b}}) +end +--]] + +Event.register(defines.events.on_tick, on_tick) +Event.register(defines.events.on_chunk_generated, on_chunk_generated) \ No newline at end of file diff --git a/poll.lua b/poll.lua index c07bf5f9..1b5ac033 100644 --- a/poll.lua +++ b/poll.lua @@ -298,16 +298,14 @@ end local function poll_timeout() if game.tick % 60 == 0 then - local x = 1 - while game.players[x] ~= nil do - local player = game.players[x] + for _, player in pairs(game.connected_players) do if global.poll_panel_creation_time[player.index] then local frame = player.gui.left["poll-panel"] if frame then local y = (game.tick - global.poll_panel_creation_time[player.index]) / 60 local y = global.poll_duration_in_seconds - y y = round(y, 0) - if y == 0 then + if y <= 0 then frame.destroy() global.poll_panel_creation_time[player.index] = nil else @@ -317,7 +315,6 @@ local function poll_timeout() end end end - x = x + 1 end end end