From 62efe899f769aa5958af6775b186b64faa6d4c16 Mon Sep 17 00:00:00 2001 From: MewMew Date: Tue, 13 Aug 2019 10:33:14 +0200 Subject: [PATCH] tweaks --- functions/unearthing_biters.lua | 62 ++++++------ maps/overgrowth.lua | 14 +-- modules/biters_attack_moving_players.lua | 31 ++++++ modules/comfylatron.lua | 19 +--- modules/evolution_extended.lua | 4 +- modules/more_attacks.lua | 2 +- modules/trees_grow.lua | 122 +++++++++++++++++------ modules/trees_randomly_die.lua | 15 ++- tools/cheat_mode.lua | 2 +- 9 files changed, 180 insertions(+), 91 deletions(-) create mode 100644 modules/biters_attack_moving_players.lua diff --git a/functions/unearthing_biters.lua b/functions/unearthing_biters.lua index ef425a58..d80c8351 100644 --- a/functions/unearthing_biters.lua +++ b/functions/unearthing_biters.lua @@ -15,34 +15,37 @@ local function create_particles(surface, position, amount) end end -local function spawn_biter(surface, position, evolution_index) - local biter_table = { - [1] = {"small-biter"}, - [2] = {"small-biter","small-biter","small-biter","small-biter","small-spitter","small-biter"}, - [3] = {"small-biter","small-biter","small-biter","small-biter","medium-biter","small-spitter"}, - [4] = {"small-biter","small-biter","small-biter","medium-biter","medium-biter","small-spitter"}, - [5] = {"small-biter","small-biter","small-biter","medium-biter","medium-biter","medium-spitter"}, - [6] = {"small-biter","small-biter","medium-biter","medium-biter","medium-biter","medium-spitter"}, - [7] = {"small-biter","medium-biter","medium-biter","medium-biter","medium-biter","medium-spitter"}, - [8] = {"medium-biter","medium-biter","medium-biter","medium-biter","big-biter","medium-spitter"}, - [9] = {"medium-biter","medium-biter","medium-biter","big-biter","big-biter","medium-spitter"}, - [10] = {"medium-biter","medium-biter","medium-biter","big-biter","big-biter","big-spitter"}, - [11] = {"medium-biter","medium-biter","big-biter","big-biter","big-biter","big-spitter"}, - [12] = {"medium-biter","big-biter","big-biter","big-biter","big-biter","big-spitter"}, - [13] = {"big-biter","big-biter","big-biter","big-biter","big-biter","big-spitter"}, - [14] = {"big-biter","big-biter","big-biter","big-biter","behemoth-biter","big-spitter"}, - [15] = {"big-biter","big-biter","big-biter","behemoth-biter","behemoth-biter","big-spitter"}, - [16] = {"big-biter","big-biter","big-biter","behemoth-biter","behemoth-biter","behemoth-spitter"}, - [17] = {"big-biter","big-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-spitter"}, - [18] = {"big-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-spitter"}, - [19] = {"behemoth-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-spitter"}, - [20] = {"behemoth-biter","behemoth-biter","behemoth-biter","behemoth-biter","behemoth-spitter","behemoth-spitter"} +local function spawn_biter(surface, position, evolution) + local evo = math.floor(evolution * 1000) + + local biter_chances = { + {name = "small-biter", chance = math.floor(1000 - (evo * 1.6))}, + {name = "small-spitter", chance = math.floor(500 - evo * 0.8)}, + {name = "medium-biter", chance = evo}, + {name = "medium-spitter", chance = math.floor(evo * 0.5)}, + {name = "big-biter", chance = math.floor((evo - 500) * 3)}, + {name = "big-spitter", chance = math.floor((evo - 500) * 2)}, + {name = "behemoth-biter", chance = math.floor((evo - 800) * 6)}, + {name = "behemoth-spitter", chance = math.floor((evo - 800) * 4)} } - local raffle = biter_table[evolution_index] - local biter_name = raffle[math.random(1,#raffle)] - local p = surface.find_non_colliding_position(biter_name, position, 10, 0.5) - if not p then return end - surface.create_entity({name = biter_name, position = p, force = "enemy"}) + + local max_chance = 0 + for i = 1, 8, 1 do + if biter_chances[i].chance < 0 then biter_chances[i].chance = 0 end + max_chance = max_chance + biter_chances[i].chance + end + local r = math.random(1, max_chance) + local current_chance = 0 + for i = 1, 8, 1 do + current_chance = current_chance + biter_chances[i].chance + if r <= current_chance then + local biter_name = biter_chances[i].name + local p = surface.find_non_colliding_position(biter_name, position, 10, 1) + if not p then return end + surface.create_entity({name = biter_name, position = p, force = "enemy"}) + return + end + end end local function unearthing_biters(surface, position, amount) @@ -51,8 +54,7 @@ local function unearthing_biters(surface, position, amount) if not position.x then return end if not position.y then return end - local evolution_index = math.ceil(game.forces.enemy.evolution_factor * 20) - if evolution_index < 1 then evolution_index = 1 end + local evolution = game.forces.enemy.evolution_factor local ticks = amount * 30 ticks = ticks + 90 @@ -68,7 +70,7 @@ local function unearthing_biters(surface, position, amount) if t % 30 == 29 then global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = { func = spawn_biter, - args = {surface, {x = position.x, y = position.y}, evolution_index} + args = {surface, {x = position.x, y = position.y}, evolution} } end end diff --git a/maps/overgrowth.lua b/maps/overgrowth.lua index 5873b9e9..736ddc35 100644 --- a/maps/overgrowth.lua +++ b/maps/overgrowth.lua @@ -8,7 +8,7 @@ require "modules.no_deconstruction_of_neutral_entities" require "modules.biters_yield_coins" require "modules.rocks_yield_ore" require "modules.ores_are_mixed" -require "modules.more_attacks" +require "modules.biters_attack_moving_players" require "modules.trees_grow" require "modules.trees_randomly_die" @@ -59,18 +59,13 @@ local function spawn_market(surface, position) market.add_market_item({price = {{"coin", 3}}, offer = {type = 'give-item', item = 'coal', count = 50}}) market.add_market_item({price = {{"coin", 5}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}}) - market.add_market_item({price = {{'coin', 4}}, offer = {type = 'give-item', item = "raw-fish", count = 1}}) + market.add_market_item({price = {{'coin', 2}}, offer = {type = 'give-item', item = "raw-fish", count = 1}}) market.add_market_item({price = {{'coin', 8}}, offer = {type = 'give-item', item = "grenade", count = 1}}) market.add_market_item({price = {{'coin', 1}}, offer = {type = 'give-item', item = "firearm-magazine", count = 1}}) market.add_market_item({price = {{'coin', 16}}, offer = {type = 'give-item', item = "submachine-gun", count = 1}}) market.add_market_item({price = {{'coin', 32}}, offer = {type = 'give-item', item = "car", count = 1}}) end -local function on_chunk_generated(event) - local surface = event.surface - local left_top = event.area.left_top -end - local function on_player_joined_game(event) local player = game.players[event.player_index] if player.online_time == 0 then @@ -80,7 +75,7 @@ local function on_player_joined_game(event) if not global.market then spawn_market(player.surface, {x = 0, y = -8}) - game.map_settings.enemy_evolution.time_factor = 0.0001 + game.map_settings.enemy_evolution.time_factor = 0.00003 global.market = true end end @@ -110,5 +105,4 @@ end event.add(defines.events.on_player_joined_game, on_player_joined_game) event.add(defines.events.on_player_mined_entity, on_player_mined_entity) -event.add(defines.events.on_entity_died, on_entity_died) -event.add(defines.events.on_chunk_generated, on_chunk_generated) \ No newline at end of file +event.add(defines.events.on_entity_died, on_entity_died) \ No newline at end of file diff --git a/modules/biters_attack_moving_players.lua b/modules/biters_attack_moving_players.lua new file mode 100644 index 00000000..20ccf526 --- /dev/null +++ b/modules/biters_attack_moving_players.lua @@ -0,0 +1,31 @@ +--moving players attract biters from far away + +local event = require 'utils.event' +local math_random = math.random + +local function on_player_changed_position(event) + if math_random(1, 128) ~= 1 then return end + if game.tick - global.biters_attack_moving_players_last_action_tick < 7200 then return end + local player = game.players[event.player_index] + if not player.character then return end + + player.surface.set_multi_command({ + command={ + type = defines.command.attack_area, + destination = player.position, + radius = 16, + distraction=defines.distraction.by_anything + }, + unit_count = math.floor(game.tick * 0.0005) + 1, + force = "enemy", + unit_search_distance=256 + }) + global.biters_attack_moving_players_last_action_tick = game.tick +end + +local function on_init(event) + global.biters_attack_moving_players_last_action_tick = 0 +end + +event.add(defines.events.on_player_changed_position, on_player_changed_position) +event.on_init(on_init) \ No newline at end of file diff --git a/modules/comfylatron.lua b/modules/comfylatron.lua index 3b5248a1..7fdf1f5e 100644 --- a/modules/comfylatron.lua +++ b/modules/comfylatron.lua @@ -20,19 +20,14 @@ local texts = { "comfylatron seeking target", "gotta go fast", "gas gas gas", - "comfylatron coming through", - "Game's over, losers! I have all the money.", - "Do the comfylatron! Do the comfylatron!" + "comfylatron coming through" }, ["greetings"] = { "=^_^=", "=^.^= Hi", "^.^ Finally i found you", "I have an important message for you", - "Hello engineer", - "Bite my 8-bit metal ass", - "I like your attitude! Let's party", - "Put it there, pal!... I meant your wallet" + "Hello engineer" }, ["neutral_findings"] = { "a", @@ -74,11 +69,7 @@ local texts = { "I dreamt of electric sheep ^_^", "I need a minute to defrag.", "I have a secret plan.", - "Good news! I’ve taught the inserter to feel love!", - "Now Wireless Joe Jackson - there was a blern-hitting machine!", - "Have you ever tried just turning off the TV, sitting down with your children, and hitting them?", - "I'm bored. Let's drink!", - "Supposing we're not stupid what kind of stupid mission is this?" + "Good news! I’ve taught the inserter to feel love!" }, ["alone"] = { "comfy ^.^", @@ -95,13 +86,9 @@ local texts = { "00010111", "10010010", "*_*", - "This is the worst kind of discrimination: the kind against me!", - "My life, and by extension everyone else's, is meaningless.", "I came here with a simple dream...a dream of killing all humans. And this is how it must end?", - "O’ cruel fate, to be thusly boned! Ask not for whom the bone bones—it bones for thee.", "Bot-on-bot violence? Where will it end?", "Thanks to you, I went on a soul-searching journey. I hate those!", - "Stupid anti-pimping laws!", "From now on, you guys'll do all the work while I sit on the couch and do nothing." } } diff --git a/modules/evolution_extended.lua b/modules/evolution_extended.lua index 7d4136b1..b529b259 100644 --- a/modules/evolution_extended.lua +++ b/modules/evolution_extended.lua @@ -8,7 +8,7 @@ local gui_refreshrate = 900 local evo_gains = { ["unit-spawner"] = 0.0025, - ["unit"] = 0.00005, + ["unit"] = 0.000025, ["turret"] = 0.001 } @@ -47,7 +47,7 @@ end local function add_evolution(amount) global.evolution_factor = global.evolution_factor + amount local evo = global.evolution_factor - if evo > 1 then evo = 1 end + if evo > 1 then evo = 1 end game.forces.enemy.evolution_factor = evo end diff --git a/modules/more_attacks.lua b/modules/more_attacks.lua index af366567..40179bdd 100644 --- a/modules/more_attacks.lua +++ b/modules/more_attacks.lua @@ -19,7 +19,7 @@ local function recruit_biters() local spawner = get_random_close_spawner(surface) if not spawner then return end - local biters = spawner.surface.find_enemy_units(spawner.position, 128, "player") + local biters = spawner.surface.find_enemy_units(spawner.position, 256, "player") if not biters[1] then return false end local amount = math.floor(game.tick * 0.001) + 1 diff --git a/modules/trees_grow.lua b/modules/trees_grow.lua index d58edd33..e4ef068c 100644 --- a/modules/trees_grow.lua +++ b/modules/trees_grow.lua @@ -7,11 +7,13 @@ local vectors = {} local r = 8 for x = r * -1, r, 0.25 do for y = r * -1, r, 0.25 do - if math.sqrt(x ^ 2 + y ^ 2) <= r then + local d = math.sqrt(x ^ 2 + y ^ 2) + if d <= r and d > 2 then vectors[#vectors + 1] = {x, y} end end end +local vectors_max_index = #vectors local immune_tiles = { ["concrete"] = true, @@ -23,46 +25,106 @@ local immune_tiles = { ["stone-path"] = true } -local function get_random_chunk_area(surface) - local p = surface.get_random_chunk() - if not p then return end - local area = {{p.x * 32, p.y * 32}, {p.x * 32 + 32, p.y * 32 + 32}} - return area +local blacklist = { + ["dead-grey-trunk"] = true +} + +local function coord_string(x, y) + str = tostring(x) .. "_" + str = str .. tostring(y) + return str end -local function grow_trees(surface) - local trees = surface.find_entities_filtered({type = "tree", area = get_random_chunk_area(surface)}) - if not trees[1] then return false end - - for a = 1, math_random(1, 6), 1 do - local tree = trees[math_random(1, #trees)] - local vector = vectors[math_random(1, #vectors)] - - local p = surface.find_non_colliding_position("car", {tree.position.x + vector[1], tree.position.y + vector[2]}, 16, 0.5) - if not p then return false end - - local tile = surface.get_tile(p) - if immune_tiles[tile.name] then - if math_random(1, 4) == 1 then - surface.set_tiles({{name = tile.hidden_tile, position = p}}) - surface.create_entity({name = tree.name, position = p, force = tree.force.name}) - end +local function is_tree_valid(surface, tree) + if not tree then return false end + if not tree.valid then return false end + if tree.surface.index ~= surface.index then return false end + return true +end + +local function shrink_table() + print("Shrinking the tree table..") + print("Old index count was " .. #global.trees_grow.raffle) + global.trees_grow.raffle = {} + for k, e in pairs(global.trees_grow.entities) do + if e.valid then + global.trees_grow.raffle[#global.trees_grow.raffle + 1] = k else - surface.create_entity({name = tree.name, position = p, force = tree.force.name}) + global.trees_grow.entities[k] = nil end end + print("New index count is " .. #global.trees_grow.raffle) +end + +local function get_random_tree(surface) + if #global.trees_grow.raffle == 0 then return false end + for a = 1, 32, 1 do + local r = math_random(1, #global.trees_grow.raffle) + local tree_coord = global.trees_grow.raffle[r] + if tree_coord then + local tree = global.trees_grow.entities[tree_coord] + if is_tree_valid(surface, tree) then + return tree + else + global.trees_grow.raffle[r] = nil + global.trees_grow.entities[tree_coord] = nil + end + end + end + shrink_table() + return false +end + +local function add_tree_entry(entity) + local str = coord_string(entity.position.x, entity.position.y) + global.trees_grow.entities[str] = entity + global.trees_grow.raffle[#global.trees_grow.raffle + 1] = str +end + +local function grow_tree(surface) + local tree = get_random_tree(surface) + if not tree then return false end + local vector = vectors[math_random(1, vectors_max_index)] + + local p = surface.find_non_colliding_position("beacon", {tree.position.x + vector[1], tree.position.y + vector[2]}, 8, 8) + if not p then return false end + + local tile = surface.get_tile(p) + if immune_tiles[tile.name] then + if math_random(1, 4) == 1 then + surface.set_tiles({{name = tile.hidden_tile, position = p}}) + add_tree_entry(surface.create_entity({name = tree.name, position = p, force = tree.force.name})) + end + else + add_tree_entry(surface.create_entity({name = tree.name, position = p, force = tree.force.name})) + end + return true end +local function on_chunk_generated(event) + local surface = event.surface + for _, e in pairs(surface.find_entities_filtered({area = event.area, type = "tree"})) do + if not blacklist[e.name] then + add_tree_entry(e) + end + end +end + local function tick(event) local surface = game.players[1].surface - - for a = 1, 16, 1 do - if grow_trees(surface) then break end + for a = 1, 32, 1 do + if grow_tree(surface) then break end end - end -event.on_nth_tick(3, tick) -event.add(defines.events.on_entity_damaged, on_entity_damaged) \ No newline at end of file +local function on_init(event) + global.trees_grow = {} + global.trees_grow.entities = {} + global.trees_grow.raffle = {} +end + +event.on_init(on_init) +event.on_nth_tick(1, tick) +event.add(defines.events.on_chunk_generated, on_chunk_generated) \ No newline at end of file diff --git a/modules/trees_randomly_die.lua b/modules/trees_randomly_die.lua index 81fcaca8..172c6a4c 100644 --- a/modules/trees_randomly_die.lua +++ b/modules/trees_randomly_die.lua @@ -35,6 +35,19 @@ local function create_particles(surface, name, position, amount) name = "fire-flame", position = {x = position.x, y = position.y} }) + + if math_random(1, 8) == 1 then + surface.create_entity({ + name = "explosive-cannon-projectile", + position = position, + force = "enemy", + source = position, + target = position, + max_range = 1, + speed = 1 + }) + + end end local r = 128 @@ -55,7 +68,7 @@ local function kill_random_tree(surface) end local function tick(event) - if math_random(1, 12) ~= 1 then return end + if math_random(1, 15) ~= 1 then return end local surface = game.players[1].surface for a = 1, 8, 1 do if kill_random_tree(surface) then return end diff --git a/tools/cheat_mode.lua b/tools/cheat_mode.lua index bbd8e164..c9a47fd3 100644 --- a/tools/cheat_mode.lua +++ b/tools/cheat_mode.lua @@ -21,7 +21,7 @@ function cheat_mode() game.forces.player.manual_mining_speed_modifier = 3 game.forces.player.character_reach_distance_bonus = 1000 game.forces.player.character_health_bonus = 1000 - game.speed = 2 + game.speed = 1 surface.daytime = 1 --surface.freeze_daytime = 1 game.player.force.research_all_technologies()