From eba6e052d28a2a3f23442b5d1a6a61732397b494 Mon Sep 17 00:00:00 2001 From: hanakocz Date: Thu, 3 Oct 2024 00:38:48 +0200 Subject: [PATCH] Initial chrono port --- maps/chronosphere/ai.lua | 127 +++-------- maps/chronosphere/balance.lua | 34 +-- maps/chronosphere/chrono.lua | 57 ++--- maps/chronosphere/comfylatron.lua | 33 ++- maps/chronosphere/event_functions.lua | 62 +++--- maps/chronosphere/gui.lua | 11 +- maps/chronosphere/main.lua | 8 +- maps/chronosphere/on_event.lua | 73 ++++++- maps/chronosphere/production.lua | 28 +-- maps/chronosphere/production_list.lua | 4 +- maps/chronosphere/raffles.lua | 36 ++-- maps/chronosphere/random.lua | 73 ------- maps/chronosphere/table.lua | 2 +- maps/chronosphere/terrain_specials.lua | 34 ++- maps/chronosphere/tick_functions.lua | 25 ++- maps/chronosphere/treasure.lua | 19 +- maps/chronosphere/upgrade_list.lua | 40 ++-- maps/chronosphere/upgrades.lua | 10 +- maps/chronosphere/world_functions.lua | 13 +- maps/chronosphere/world_list.lua | 35 ++-- maps/chronosphere/worlds/basic.lua | 2 +- maps/chronosphere/worlds/blueprints.lua | 2 + maps/chronosphere/worlds/caveworld.lua | 2 +- .../worlds/locomotive_surface.lua | 197 +++++++++++------- maps/chronosphere/worlds/maze.lua | 2 +- maps/chronosphere/worlds/swamp.lua | 2 +- maps/expanse/main.lua | 7 +- modules/admins_operate_biters.lua | 89 ++------ modules/biters_yield_coins.lua | 4 +- modules/biters_yield_ore.lua | 2 +- utils/functions/AI.lua | 108 ++++++++++ 31 files changed, 592 insertions(+), 549 deletions(-) delete mode 100644 maps/chronosphere/random.lua create mode 100644 utils/functions/AI.lua diff --git a/maps/chronosphere/ai.lua b/maps/chronosphere/ai.lua index ffe8039e..2c0c3f1f 100644 --- a/maps/chronosphere/ai.lua +++ b/maps/chronosphere/ai.lua @@ -1,8 +1,8 @@ local Chrono_table = require 'maps.chronosphere.table' local Balance = require 'maps.chronosphere.balance' local Difficulty = require 'modules.difficulty_vote' -local Rand = require 'maps.chronosphere.random' local Raffle = require 'maps.chronosphere.raffles' +local AI = require 'utils.functions.AI' local Public = {} local random = math.random @@ -24,83 +24,6 @@ local fish_area = { left_top = { -1100, -400 }, right_bottom = { 1100, 400 } } -----------commands----------- -local function move_to(position) - local command = { - type = defines.command.go_to_location, - destination = position, - distraction = defines.distraction.by_anything - } - return command -end - -local function attack_target(target) - if not target.valid then - return - end - local command = { - type = defines.command.attack, - target = target, - distraction = defines.distraction.by_anything - } - return command -end - -local function attack_area(position, radius) - local command = { - type = defines.command.attack_area, - destination = position, - radius = radius or 25, - distraction = defines.distraction.by_anything - } - return command -end - -local function attack_obstacles(surface, position) - local commands = {} - local obstacles = surface.find_entities_filtered { position = position, radius = 25, type = { 'simple-entity', 'tree', 'simple-entity-with-owner' }, limit = 100 } - if obstacles then - Rand.shuffle(obstacles) - Rand.shuffle_distance(obstacles, position) - for i = 1, #obstacles, 1 do - if obstacles[i].valid then - commands[#commands + 1] = { - type = defines.command.attack, - target = obstacles[i], - distraction = defines.distraction.by_anything - } - end - end - end - commands[#commands + 1] = move_to(position) - local command = { - type = defines.command.compound, - structure_type = defines.compound_command.return_last, - commands = commands - } - return command -end - -local function multicommand(group, commands) - if #commands > 0 then - local command = { - type = defines.command.compound, - structure_type = defines.compound_command.return_last, - commands = commands - } - group.set_command(command) - end -end - -local function multi_attack(surface, target) - surface.set_multi_command( - { - command = attack_target(target), - unit_count = 16 + random(1, floor(1 + game.forces['enemy'].evolution_factor * 100)) * Difficulty.get().difficulty_vote_value, - force = 'enemy', - unit_search_distance = 1024 - } - ) -end ------------------------misc functions---------------------- @@ -141,13 +64,13 @@ local function generate_side_attack_target(surface, position, area) goto retry end end - entities = Rand.shuffle(entities) - entities = Rand.shuffle_distance(entities, position) + table.shuffle_table(entities) + table.shuffle_by_distance(entities, position) local weights = {} for index, _ in pairs(entities) do weights[#weights + 1] = 1 + floor((#entities - index) / 2) end - return Rand.raffle(entities, weights) + return table.get_random_weighted_t(entities, weights) end local function generate_main_attack_target() @@ -173,13 +96,13 @@ local function get_random_close_spawner(surface) if not spawners[1] then return false end - spawners = Rand.shuffle(spawners) - spawners = Rand.shuffle_distance(spawners, objective.locomotive.position) + table.shuffle_table(spawners) + table.shuffle_by_distance(spawners, objective.locomotive.position) local weights = {} for index, _ in pairs(spawners) do weights[#weights + 1] = 1 + floor((#spawners - index) / 2) end - return Rand.raffle(spawners, weights), area + return table.get_random_weighted_t(spawners, weights), area end local function is_biter_inactive(biter) @@ -189,10 +112,10 @@ local function is_biter_inactive(biter) if not biter.entity.valid then return true end - if not biter.entity.unit_group then + if not biter.entity.commandable then return true end - if not biter.entity.unit_group.valid then + if not biter.entity.commandable.valid then return true end if game.tick - biter.active_since > 162000 then @@ -258,10 +181,10 @@ local function select_units_around_spawner(spawner, size) local local_pollution = math.min( spawner.surface.get_pollution(spawner.position), - 400 * game.map_settings.pollution.enemy_attack_pollution_consumption_modifier * game.forces.enemy.evolution_factor + 400 * game.map_settings.pollution.enemy_attack_pollution_consumption_modifier * game.forces.enemy.get_evolution_factor(spawner.surface) ) spawner.surface.pollute(spawner.position, -local_pollution) - game.pollution_statistics.on_flow('biter-spawner', -local_pollution) + game.get_pollution_statistics(spawner.surface).on_flow('biter-spawner', -local_pollution) if local_pollution < 1 then break end @@ -290,7 +213,7 @@ local function pollution_requirement(surface, position, main) end if pollution > multiplier * pollution_to_eat then surface.pollute(position, -pollution_to_eat) - game.pollution_statistics.on_flow('small-biter', -pollution_to_eat) + game.get_pollution_statistics(surface).on_flow('small-biter', -pollution_to_eat) return true end return false @@ -343,14 +266,14 @@ end local function colonize(group) --if _DEBUG then game.print(game.tick ..": colonizing") end local surface = group.surface - local evo = group.force.evolution_factor + local evo = group.force.get_evolution_factor(surface) local nests = random(1 + floor(evo * 20), 2 + floor(evo * 20) * 2) local commands = {} local biters = surface.find_entities_filtered { position = group.position, radius = 30, name = Raffle.biters, force = 'enemy' } local goodbiters = {} if #biters > 1 then for i = 1, #biters, 1 do - if biters[i].unit_group == group then + if biters[i].commandable == group then goodbiters[#goodbiters + 1] = biters[i] end end @@ -381,7 +304,7 @@ local function colonize(group) end else commands = { - attack_obstacles(surface, group.position) + AI.command_attack_obstacles(surface, group.position) } end end @@ -395,7 +318,7 @@ local function colonize(group) end if #commands > 0 then --game.print("Attacking [gps=" .. commands[1].target.position.x .. "," .. commands[1].target.position.y .. "]") - multicommand(group, commands) + AI.multicommand(group, commands) end end @@ -412,7 +335,7 @@ local function send_near_biters_to_objective() if _DEBUG then game.print(game.tick .. ': sending objective wave') end - multi_attack(target.surface, target) + AI.multi_attack(target.surface, target, game.forces.enemy) end end @@ -420,16 +343,16 @@ local function attack_check(group, target, main) local commands if pollution_requirement(group.surface, target.position, main) then commands = { - attack_target(target), - attack_area(target.position, 32) + AI.command_attack_target(target), + AI.command_attack_area(target.position, 32) } else local position = generate_expansion_position(group.position) commands = { - attack_obstacles(group.surface, position) + AI.command_attack_obstacles(group.surface, position) } end - multicommand(group, commands) + AI.multicommand(group, commands) end local function give_new_orders(group) @@ -442,10 +365,10 @@ local function give_new_orders(group) return end local commands = { - attack_target(target), - attack_area(target.position, 32) + AI.command_attack_target(target), + AI.command_attack_area(target.position, 32) } - multicommand(group, commands) + AI.multicommand(group, commands) end ------------------------- tick minute functions-------------------- @@ -453,7 +376,7 @@ end local function destroy_inactive_biters() local bitertable = Chrono_table.get_biter_table() for unit_number, biter in pairs(bitertable.active_biters) do - if is_biter_inactive(biter, unit_number) then + if is_biter_inactive(biter) then bitertable.active_biters[unit_number] = nil bitertable.free_biters = bitertable.free_biters + 1 end diff --git a/maps/chronosphere/balance.lua b/maps/chronosphere/balance.lua index b7501708..d51336d5 100644 --- a/maps/chronosphere/balance.lua +++ b/maps/chronosphere/balance.lua @@ -235,24 +235,24 @@ Public.dayspeed_weights = { } function Public.market_offers() return { - {price = {{'coin', 40}}, offer = {type = 'give-item', item = 'raw-fish'}}, - {price = {{'coin', 40}}, offer = {type = 'give-item', item = 'wood', count = 50}}, - {price = {{'coin', 100}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}}, - {price = {{'coin', 100}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}}, - {price = {{'coin', 100}}, offer = {type = 'give-item', item = 'stone', count = 50}}, -- needed? - {price = {{'coin', 100}}, offer = {type = 'give-item', item = 'coal', count = 50}}, - {price = {{'coin', 400}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}}, - {price = {{'coin', 50}, {'empty-barrel', 1}}, offer = {type = 'give-item', item = 'crude-oil-barrel', count = 1}}, - {price = {{'coin', 500}, {'steel-plate', 20}, {'electronic-circuit', 20}}, offer = {type = 'give-item', item = 'loader', count = 1}}, + {price = {{name = 'coin', count = 40}}, offer = {type = 'give-item', item = 'raw-fish'}}, + {price = {{name = 'coin', count = 40}}, offer = {type = 'give-item', item = 'wood', count = 50}}, + {price = {{name = 'coin', count = 100}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}}, + {price = {{name = 'coin', count = 100}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}}, + {price = {{name = 'coin', count = 100}}, offer = {type = 'give-item', item = 'stone', count = 50}}, -- needed? + {price = {{name = 'coin', count = 100}}, offer = {type = 'give-item', item = 'coal', count = 50}}, + {price = {{name = 'coin', count = 400}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}}, + {price = {{name = 'coin', count = 50}, {name = 'barrel', count = 1}}, offer = {type = 'give-item', item = 'crude-oil-barrel', count = 1}}, + {price = {{name = 'coin', count = 500}, {name = 'steel-plate', count = 20}, {name = 'electronic-circuit', count = 20}}, offer = {type = 'give-item', item = 'loader', count = 1}}, { - price = {{'coin', 1000}, {'steel-plate', 40}, {'advanced-circuit', 10}, {'loader', 1}}, + price = {{name = 'coin', count = 1000}, {name = 'steel-plate', count = 40}, {name = 'advanced-circuit', count = 10}, {name = 'loader', count = 1}}, offer = {type = 'give-item', item = 'fast-loader', count = 1} }, { - price = {{'coin', 3000}, {'express-transport-belt', 10}, {'fast-loader', 1}}, + price = {{name = 'coin', count = 3000}, {name = 'express-transport-belt', count = 10}, {name = 'fast-loader', count = 1}}, offer = {type = 'give-item', item = 'express-loader', count = 1} }, - {price = {{'coin', 2}, {'steel-plate', 1}, {'explosives', 10}}, offer = {type = 'give-item', item = 'land-mine', count = 1}} + {price = {{name = 'coin', count = 2}, {name = 'steel-plate', count = 1}, {name = 'explosives', count = 10}}, offer = {type = 'give-item', item = 'land-mine', count = 1}} } end function Public.initial_cargo_boxes() @@ -262,7 +262,7 @@ function Public.initial_cargo_boxes() {name = 'coal', count = math_random(32, 64)}, {name = 'iron-ore', count = math_random(32, 128)}, {name = 'copper-ore', count = math_random(32, 128)}, - {name = 'empty-barrel', count = math_random(16, 32)}, + {name = 'barrel', count = math_random(16, 32)}, {name = 'submachine-gun', count = 1}, {name = 'submachine-gun', count = 1}, {name = 'shotgun', count = 1}, @@ -324,7 +324,7 @@ function Public.scrap() ['processing-unit'] = {amount = 2, chance = 1}, ['used-up-uranium-fuel-cell'] = {amount = 1, chance = 4}, ['uranium-fuel-cell'] = {amount = 0.3, chance = 1}, - ['rocket-control-unit'] = {amount = 0.3, chance = 1}, + --['rocket-control-unit'] = {amount = 0.3, chance = 1}, ['low-density-structure'] = {amount = 0.5, chance = 2}, ['heat-pipe'] = {amount = 1, chance = 1}, ['engine-unit'] = {amount = 3, chance = 3}, @@ -353,7 +353,7 @@ function Public.scrap() ['rocket-fuel'] = {amount = 0.3, chance = 8}, ['grenade'] = {amount = 0.3, chance = 40}, ['solid-fuel'] = {amount = 0.4, chance = 50}, - ['empty-barrel'] = {amount = 0.1, chance = 50}, + ['barrel'] = {amount = 0.1, chance = 50}, ['crude-oil-barrel'] = {amount = 0.1, chance = 70}, ['lubricant-barrel'] = {amount = 0.1, chance = 40}, ['petroleum-gas-barrel'] = {amount = 0.1, chance = 60}, @@ -375,8 +375,8 @@ function Public.scrap() table.insert(second_raffle, {name = k, amount = t.amount}) end end - Rand.shuffle(scrap_raffle) - Rand.shuffle(second_raffle) + table.shuffle_table(scrap_raffle) + table.shuffle_table(second_raffle) return {main = scrap_raffle, second = second_raffle} end diff --git a/maps/chronosphere/chrono.lua b/maps/chronosphere/chrono.lua index d62b7ce0..75c2beb6 100644 --- a/maps/chronosphere/chrono.lua +++ b/maps/chronosphere/chrono.lua @@ -11,22 +11,28 @@ local Server = require 'utils.server' local math_random = math.random local math_max = math.max -function Public.get_map_gen_settings() +function Public.get_map_gen_settings(planet_name) local seed = math_random(1, 1000000) - local map_gen_settings = { - ['seed'] = seed, - ['width'] = 960, - ['height'] = 960, - ['water'] = 0.1, - ['starting_area'] = 1, - ['cliff_settings'] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}, - ['default_enable_all_autoplace_controls'] = true, - ['autoplace_settings'] = { - ['entity'] = {treat_missing_as_default = false}, - ['tile'] = {treat_missing_as_default = true}, - ['decorative'] = {treat_missing_as_default = true} - } - } + local map_gen_settings = prototypes.space_location['nauvis'].map_gen_settings + -- if planet_name then + -- map_gen_settings = prototypes.space_location[planet_name].map_gen_settings + -- else + -- map_gen_settings = { + -- ['water'] = 0.1, + -- ['default_enable_all_autoplace_controls'] = true, + -- ['autoplace_settings'] = { + -- ['entity'] = {treat_missing_as_default = false}, + -- ['tile'] = {treat_missing_as_default = true}, + -- ['decorative'] = {treat_missing_as_default = true} + -- } + -- } + -- end + map_gen_settings.seed = seed + map_gen_settings.width = 960 + map_gen_settings.height = 960 + map_gen_settings.starting_area = 1 + map_gen_settings.cliff_settings = {name = 'cliff', cliff_elevation_interval = 0, cliff_elevation_0 = 0, cliff_smoothing = 0.5, richness = 0} + map_gen_settings.default_enable_all_autoplace_controls = false return map_gen_settings end @@ -115,9 +121,9 @@ function Public.restart_settings() for _, player in pairs(game.connected_players) do playertable.flame_boots[player.index] = {fuel = 1, steps = {}} end - global.friendly_fire_history = {} - global.landfill_history = {} - global.mining_history = {} + storage.friendly_fire_history = {} + storage.landfill_history = {} + storage.mining_history = {} get_score.score_table = {} game.difficulty_settings.technology_price_multiplier = Balance.Tech_price_multiplier @@ -150,18 +156,18 @@ function Public.restart_settings() game.map_settings.path_finder.long_cache_size = 100 game.map_settings.unit_group.max_gathering_unit_groups = 10 game.forces.neutral.character_inventory_slots_bonus = 500 - game.forces.enemy.evolution_factor = 0.0001 + game.forces.enemy.set_evolution_factor(0.0001) game.forces.scrapyard.set_friend('enemy', true) game.forces.enemy.set_friend('scrapyard', true) game.forces.enemy.set_ammo_damage_modifier('rocket', -0.5) game.forces.player.technologies['land-mine'].enabled = false game.forces.player.technologies['landfill'].enabled = false game.forces.player.technologies['cliff-explosives'].enabled = false - game.forces.player.technologies['fusion-reactor-equipment'].enabled = false + game.forces.player.technologies['fission-reactor-equipment'].enabled = false game.forces.player.technologies['power-armor-mk2'].enabled = false game.forces.player.technologies['railway'].researched = true game.forces.player.recipes['pistol'].enabled = false - game.forces.player.ghost_time_to_live = 15 * 60 * 60 + --game.forces.player.ghost_time_to_live = 15 * 60 * 60 end function Public.set_difficulty_settings() @@ -331,10 +337,11 @@ function Public.post_jump() local difficulty = Difficulty.get().difficulty_vote_value game.forces.enemy.reset_evolution() + local surface = game.get_surface(objective.active_surface_index) if objective.chronojumps + objective.overstaycount <= 40 and objective.world.id ~= 7 then - game.forces.enemy.evolution_factor = 0 + 0.025 * (objective.chronojumps + objective.overstaycount) + game.forces.enemy.set_evolution_factor(0 + 0.025 * (objective.chronojumps + objective.overstaycount), surface) else - game.forces.enemy.evolution_factor = 1 + game.forces.enemy.set_evolution_factor(1, surface) end if objective.world.id == 7 then objective.locomotive_cargo[1].insert({name = 'space-science-pack', count = 1000}) @@ -367,7 +374,7 @@ function Public.post_jump() game.forces.enemy.set_ammo_damage_modifier('melee', 0.1 * objective.overstaycount) game.forces.enemy.set_ammo_damage_modifier('biological', 0.1 * objective.overstaycount) game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = Balance.defaultai_attack_pollution_consumption_modifier(difficulty) - game.map_settings.pollution.max_unit_group_size = Balance.max_new_attack_group_size(difficulty) + --game.map_settings.pollution.max_unit_group_size = Balance.max_new_attack_group_size(difficulty) if objective.chronojumps == 1 then if difficulty < 1 then @@ -403,7 +410,7 @@ local function create_chunk_list(surface) chunks[#chunks + 1] = {pos = {x, y}, generated = surface.is_chunk_generated({x, y}), distance = math.sqrt(x * x + y * y)} end end - for k, v in Rand.spairs( + for k, v in table.spairs( chunks, function(t, a, b) return t[b].distance > t[a].distance diff --git a/maps/chronosphere/comfylatron.lua b/maps/chronosphere/comfylatron.lua index 22ac4acf..85192d81 100644 --- a/maps/chronosphere/comfylatron.lua +++ b/maps/chronosphere/comfylatron.lua @@ -4,6 +4,7 @@ local math_random = math.random local Rand = require 'maps.chronosphere.random' local Balance = require 'maps.chronosphere.balance' local Difficulty = require 'modules.difficulty_vote' +local FT = require 'utils.functions.flying_texts' local Public = {} local texts = { @@ -294,6 +295,15 @@ local texts = { } } +local function get_comfylatron_kind() + local SA = script.active_mods['space-travel'] + if SA then + return 'small-strafer-pentapod' + else + return 'behemoth-biter' + end +end + local function set_comfy_speech_bubble(text) local objective = Chrono_table.get_table() if objective.comfybubble then @@ -365,7 +375,7 @@ local function visit_player() end local player = players[math_random(1, #players)] - objective.comfylatron.set_command( + objective.comfylatron.commandable.set_command( { type = defines.command.go_to_location, destination_entity = player.character, @@ -509,16 +519,16 @@ local function desync(event) ) end local blocked = false - if not objective.comfylatron.surface.find_non_colliding_position('compilatron', objective.comfylatron.position, 0.5, 0.1) then + if not objective.comfylatron.surface.find_non_colliding_position(get_comfylatron_kind(), objective.comfylatron.position, 0.5, 0.1) then blocked = true end if not event or blocked or math_random(1, 5) == 1 then objective.comfylatron.surface.create_entity({name = 'medium-explosion', position = objective.comfylatron.position}) - objective.comfylatron.surface.create_entity({name = 'flying-text', position = objective.comfylatron.position, text = 'desync', color = {r = 150, g = 0, b = 0}}) + FT.flying_text(nil, objective.comfylatron.surface, objective.comfylatron.position, 'desync', {r = 150, g = 0, b = 0}) objective.comfylatron.destroy() objective.comfylatron = nil else - objective.comfylatron.surface.create_entity({name = 'flying-text', position = objective.comfylatron.position, text = 'desync evaded', color = {r = 0, g = 150, b = 0}}) + FT.flying_text(nil, objective.comfylatron.surface, objective.comfylatron.position, 'desync evaded', {r = 0, g = 150, b = 0}) if event.cause then if event.cause.valid and event.cause.player then game.print({'chronosphere.message_comfylatron_desync', event.cause.player.name}, {r = 200, g = 0, b = 0}) @@ -547,7 +557,8 @@ local function alone() end local analyze_blacklist = { - ['compilatron'] = true, + ['small-strafer-pentapod'] = true, + ['behemoth-biter'] = true, ['car'] = true, ['compi-speech-bubble'] = true, ['entity-ghost'] = true, @@ -572,7 +583,7 @@ local function analyze_random_nearby_entity() if not entities[1] then return false end - entities = Rand.shuffle(entities) + table.shuffle_table(entities) local entity = false for _, e in pairs(entities) do if not analyze_blacklist[e.name] then @@ -603,7 +614,7 @@ local function analyze_random_nearby_entity() set_comfy_speech_bubble(str) if not objective.comfylatron_greet_player_index then - objective.comfylatron.set_command( + objective.comfylatron.commandable.set_command( { type = defines.command.go_to_location, destination_entity = entity, @@ -640,7 +651,7 @@ local function go_to_some_location() objective.comfylatron_greet_player_index = nil return false end - objective.comfylatron.set_command( + objective.comfylatron.commandable.set_command( { type = defines.command.go_to_location, destination_entity = player.character, @@ -655,14 +666,14 @@ local function go_to_some_location() ) else local p = {x = objective.comfylatron.position.x + (-96 + math_random(0, 192)), y = objective.comfylatron.position.y + (-96 + math_random(0, 192))} - local target = objective.comfylatron.surface.find_non_colliding_position('compilatron', p, 8, 1) + local target = objective.comfylatron.surface.find_non_colliding_position(get_comfylatron_kind(), p, 8, 1) if not target then return false end if not is_target_inside_habitat(target, objective.comfylatron.surface) then return false end - objective.comfylatron.set_command( + objective.comfylatron.commandable.set_command( { type = defines.command.go_to_location, destination = target, @@ -707,7 +718,7 @@ local function spawn_comfylatron(surface_index, x, y) objective.comfylatron = surface.create_entity( { - name = 'compilatron', + name = get_comfylatron_kind(), position = {x, y + math_random(0, 256)}, force = 'player', create_build_effect_smoke = false diff --git a/maps/chronosphere/event_functions.lua b/maps/chronosphere/event_functions.lua index 07e8f961..d7d0d4e7 100644 --- a/maps/chronosphere/event_functions.lua +++ b/maps/chronosphere/event_functions.lua @@ -8,6 +8,7 @@ local Public = {} local tick_tack_trap = require 'utils.functions.tick_tack_trap' local unearthing_worm = require 'utils.functions.unearthing_worm' local unearthing_biters = require 'utils.functions.unearthing_biters' +local FT = require 'utils.functions.flying_texts' local math_random = math.random local math_floor = math.floor @@ -59,17 +60,6 @@ local function reward_ores(amount, mined_loot, surface, player, entity) end end -local function flying_text(surface, position, text, color) - surface.create_entity( - { - name = 'flying-text', - position = {position.x, position.y - 0.5}, - text = text, - color = color - } - ) -end - function Public.biters_chew_rocks_faster(event) if not event.cause then return @@ -123,7 +113,7 @@ end function Public.lava_planet(event) local playertable = Chrono_table.get_player_table() local player = game.get_player(event.player_index) - if not player.character then + if not player or not player.character then return end if player.character.driving then @@ -159,7 +149,7 @@ function Public.lava_planet(event) end function Public.shred_simple_entities(entity) - if game.forces.enemy.evolution_factor < 0.25 then + if game.forces.enemy.get_evolution_factor(entity.surface) < 0.25 then return end local simple_entities = entity.surface.find_entities_filtered({type = {'simple-entity', 'tree'}, area = {{entity.position.x - 3, entity.position.y - 3}, {entity.position.x + 3, entity.position.y + 3}}}) @@ -175,7 +165,7 @@ function Public.spawner_loot(surface, position) local objective = Chrono_table.get_table() local count = math_random(1, 1 + objective.chronojumps) objective.research_tokens.weapons = objective.research_tokens.weapons + count - flying_text(surface, position, {'chronosphere.token_weapons_add', count}, {r = 0.8, g = 0.8, b = 0.8}) + FT.flying_text(nil, surface, position, {'chronosphere.token_weapons_add', count}, {r = 0.8, g = 0.8, b = 0.8}) script.raise_event(Chrono_table.events['update_upgrades_gui'], {}) end end @@ -217,7 +207,7 @@ function Public.choppy_loot(event) local main_item = choppy_entity_yield[entity.name][math_random(1, #choppy_entity_yield[entity.name])] local text = '+' .. amount .. ' [item=' .. main_item .. '] +' .. second_item_amount .. ' [item=' .. second_item .. ']' local player = game.get_player(event.player_index) - flying_text(entity.surface, entity.position, text, {r = 0.8, g = 0.8, b = 0.8}) + FT.flying_text(player, entity.surface, entity.position, text, {r = 0.8, g = 0.8, b = 0.8}) reward_ores(amount, main_item, entity.surface, player, player) reward_ores(second_item_amount, second_item, entity.surface, player, player) end @@ -225,11 +215,12 @@ end function Public.rocky_loot(event) local player = game.get_player(event.player_index) + if not player or not player.valid then return end local amount = math_ceil(get_ore_amount(false)) local rock_mining = {'iron-ore', 'iron-ore', 'iron-ore', 'iron-ore', 'copper-ore', 'copper-ore', 'copper-ore', 'stone', 'stone', 'coal', 'coal'} local mined_loot = rock_mining[math_random(1, #rock_mining)] local text = '+' .. amount .. ' [item=' .. mined_loot .. ']' - flying_text(player.surface, player.position, text, {r = 0.98, g = 0.66, b = 0.22}) + FT.flying_text(player, player.surface, player.position, text, {r = 0.98, g = 0.66, b = 0.22}) reward_ores(amount, mined_loot, player.surface, player, player) reward_ores(math_random(1, 3), 'raw-fish', player.surface, player, player) end @@ -242,13 +233,14 @@ function Public.scrap_loot(event) local amount = math_ceil(get_ore_amount(true) * scrap.amount) local amount2 = math_ceil(get_ore_amount(true) * scrap2.amount) local player = game.get_player(event.player_index) + if not player or not player.valid then return end local text = '+' .. amount .. ' [item=' .. scrap.name .. '] + ' .. amount2 .. ' [item=' .. scrap2.name .. ']' - flying_text(player.surface, player.position, text, {r = 0.98, g = 0.66, b = 0.22}) + FT.flying_text(player, player.surface, player.position, text, {r = 0.98, g = 0.66, b = 0.22}) reward_ores(amount, scrap.name, player.surface, player, player) reward_ores(amount2, scrap2.name, player.surface, player, player) if math_random(1, 50) == 1 then objective.research_tokens.tech = objective.research_tokens.tech + 1 - flying_text(player.surface, {x = player.position.x, y = player.position.y - 0.5}, {'chronosphere.token_tech_add', 1}, {r = 0.8, g = 0.8, b = 0.8}) + FT.flying_text(player, player.surface, {x = player.position.x, y = player.position.y - 0.5}, {'chronosphere.token_tech_add', 1}, {r = 0.8, g = 0.8, b = 0.8}) end end @@ -284,7 +276,7 @@ function Public.swamp_loot(event) local mined_loot = rock_mining[math_random(1, #rock_mining)] reward_ores(amount, mined_loot, surface, nil, event.entity) local text = '+' .. amount .. ' [img=item/' .. mined_loot .. ']' - flying_text(surface, event.entity.position, text, {r = 0.7, g = 0.8, b = 0.4}) + FT.flying_text(nil, surface, event.entity.position, text, {r = 0.7, g = 0.8, b = 0.4}) end function Public.biter_loot(event) @@ -308,8 +300,8 @@ function Public.danger_silo(entity) objective.dangers[i].solar.destroy() objective.dangers[i].acu.destroy() objective.dangers[i].pole.destroy() - rendering.destroy(objective.dangers[i].text) - rendering.destroy(objective.dangers[i].timer) + objective.dangers[i].text.destroy() + objective.dangers[i].timer.destroy() objective.dangers[i].text = -1 objective.dangers[i].timer = -1 end @@ -426,12 +418,12 @@ function Public.on_technology_effects_reset(event) local fake_event = {} Public.mining_buffs(nil) - for tech, bonuses in pairs(mining_researches) do - tech = force.technologies[tech] - if tech.researched == true or bonuses.infinite == true then - fake_event.research = tech - if bonuses.infinite and bonuses.infinite_level and tech.level > bonuses.infinite_level then - for i = bonuses.infinite_level, tech.level - 1 do + for name, bonuses in pairs(mining_researches) do + technology = force.technologies[name] + if technology.researched == true or bonuses.infinite == true then + fake_event.research = technology + if bonuses.infinite and bonuses.infinite_level and technology.level > bonuses.infinite_level then + for i = bonuses.infinite_level, technology.level - 1 do Public.mining_buffs(fake_event) end else @@ -462,8 +454,11 @@ function Public.render_train_hp() rendering.draw_text { text = {'chronosphere.train_HP', objective.health, objective.max_health}, surface = surface, - target = objective.locomotive, - target_offset = {0, -2.5}, + target = { + entity = objective.locomotive, + offset = {0, -2.5}, + position = objective.locomotive.position + }, color = objective.locomotive.color, scale = 1.40, font = 'default-game', @@ -474,8 +469,11 @@ function Public.render_train_hp() rendering.draw_text { text = {'chronosphere.train_name'}, surface = surface, - target = objective.locomotive, - target_offset = {0, -4.25}, + target = { + entity = objective.locomotive, + offset = {0, -4.25}, + position = objective.locomotive.position + }, color = objective.locomotive.color, scale = 1.80, font = 'default-game', @@ -500,7 +498,7 @@ function Public.set_objective_health(final_damage_amount) if objective.health < objective.max_health / 2 and final_damage_amount > 0 then Upgrades.trigger_poison() end - rendering.set_text(objective.health_text, {'chronosphere.train_HP', objective.health, objective.max_health}) + objective.health_text.text = {'chronosphere.train_HP', objective.health, objective.max_health} end function Public.nuclear_artillery(entity, cause) diff --git a/maps/chronosphere/gui.lua b/maps/chronosphere/gui.lua index d1d3c3e1..aa7ca189 100644 --- a/maps/chronosphere/gui.lua +++ b/maps/chronosphere/gui.lua @@ -40,8 +40,7 @@ local function create_gui(player) label.style.minimal_width = 10 label.style.font_color = {r = 255, g = 200, b = 200} - local progressbar = frame.add({type = 'progressbar', name = 'progressbar', value = 0}) - progressbar.style = 'achievement_progressbar' + local progressbar = frame.add({type = 'progressbar', name = 'progressbar', value = 0, style = 'achievement_progressbar'}) progressbar.style.minimal_width = 96 progressbar.style.maximal_width = 96 progressbar.style.top_padding = 1 @@ -238,7 +237,7 @@ local function update_world_gui(player) local difficulty = Difficulty.get().difficulty_vote_value local overstay_jump = Balance.jumps_until_overstay_is_on(difficulty) or 3 local world = objective.world - local evolution = game.forces['enemy'].evolution_factor + local evolution = game.forces['enemy'].get_evolution_factor(game.get_surface(objective.active_surface_index)) local evo_color = { r = math_floor(255 * 1 * math_max(0, math_min(1, 1.2 - evolution * 2))), g = math_floor(255 * 1 * math_max(math_abs(0.5 - evolution * 1.5), 1 - evolution * 4)), @@ -254,7 +253,7 @@ local function update_world_gui(player) frame['world_ores']['uranium-ore'].number = world.variant.u frame['world_ores']['oil'].number = world.variant.o frame['richness'].caption = {'chronosphere.gui_world_2', world.ores.name} - frame['world_biters'].caption = {'chronosphere.gui_world_3', math_floor(evolution * 100, 1)} + frame['world_biters'].caption = {'chronosphere.gui_world_3', math_floor(evolution * 100)} frame['world_biters'].style.font_color = evo_color frame['world_biters3'].caption = {'chronosphere.gui_world_4_1', objective.overstaycount * 2.5, objective.overstaycount * 10} @@ -291,7 +290,7 @@ local function world_gui(player) end local objective = Chrono_table.get_table() local world = objective.world - local evolution = game.forces['enemy'].evolution_factor + local evolution = game.forces['enemy'].get_evolution_factor(game.get_surface(objective.active_surface_index)) local frame = player.gui.screen.add {type = 'frame', name = 'gui_world', caption = {'chronosphere.gui_world_button'}, direction = 'vertical'} frame.location = {x = 650, y = 45} frame.style.minimal_height = 300 @@ -310,7 +309,7 @@ local function world_gui(player) frame.add({type = 'label', name = 'richness', caption = {'chronosphere.gui_world_2', world.ores.name}}) frame.add({type = 'label', name = 'world_time', caption = {'chronosphere.gui_world_5', world.dayspeed.name}}) frame.add({type = 'line'}) - frame.add({type = 'label', name = 'world_biters', caption = {'chronosphere.gui_world_3', math_floor(evolution * 100, 1)}}) + frame.add({type = 'label', name = 'world_biters', caption = {'chronosphere.gui_world_3', math_floor(evolution * 100)}}) frame.add({type = 'label', name = 'world_biters2', caption = {'chronosphere.gui_world_4'}}) frame.add({type = 'label', name = 'world_biters3', caption = {'chronosphere.gui_world_4_1', objective.overstaycount * 2.5, objective.overstaycount * 10}}) frame.add({type = 'line'}) diff --git a/maps/chronosphere/main.lua b/maps/chronosphere/main.lua index 8a8cdcdb..206df9af 100644 --- a/maps/chronosphere/main.lua +++ b/maps/chronosphere/main.lua @@ -43,10 +43,11 @@ local function reset_map() Worlds.determine_world(nil) local world = objective.world if not objective.active_surface_index then - objective.active_surface_index = game.create_surface('chronosphere', Chrono.get_map_gen_settings()).index + objective.active_surface_index = game.create_surface('chronosphere', Chrono.get_map_gen_settings(world.planet_name)).index + --/c game.create_surface("pizza", prototypes.space_location["gleba"].map_gen_settings) else game.forces.player.set_spawn_position({12, 10}, game.surfaces[objective.active_surface_index]) - objective.active_surface_index = Reset.soft_reset_map(game.surfaces[objective.active_surface_index], Chrono.get_map_gen_settings(), Balance.starting_items).index + objective.active_surface_index = Reset.soft_reset_map(game.surfaces[objective.active_surface_index], Chrono.get_map_gen_settings(world.planet_name), Balance.starting_items).index end local surface = game.surfaces[objective.active_surface_index] @@ -110,7 +111,8 @@ local function chronojump(choice) end end scheduletable.lab_cells = {} - objective.active_surface_index = game.create_surface('chronosphere' .. objective.chronojumps, Chrono.get_map_gen_settings()).index + Worlds.determine_world(nil) + objective.active_surface_index = game.create_surface('chronosphere' .. objective.chronojumps, Chrono.get_map_gen_settings(objective.world.planet_name)).index local surface = game.surfaces[objective.active_surface_index] generate_overworld(surface, choice) diff --git a/maps/chronosphere/on_event.lua b/maps/chronosphere/on_event.lua index ca61a994..915b672e 100644 --- a/maps/chronosphere/on_event.lua +++ b/maps/chronosphere/on_event.lua @@ -34,7 +34,7 @@ function Public.on_player_mined_entity(event) Event_functions.trap(entity, false) Event_functions.choppy_loot(event) end - elseif entity.name == 'rock-huge' or entity.name == 'rock-big' or entity.name == 'sand-rock-big' then + elseif entity.name == 'huge-rock' or entity.name == 'big-rock' or entity.name == 'big-sand-rock' then if objective.world.id == 3 then --rocky worlds event.buffer.clear() -- elseif objective.world.id == 5 then --maze worlds @@ -51,7 +51,7 @@ end function Public.pre_player_mined_item(event) local objective = Chrono_table.get_table() if objective.world.id == 3 then --rocky worlds - if event.entity.name == 'rock-huge' or event.entity.name == 'rock-big' or event.entity.name == 'sand-rock-big' then + if event.entity.name == 'huge-rock' or event.entity.name == 'big-rock' or event.entity.name == 'big-sand-rock' then Event_functions.trap(event.entity, false) event.entity.destroy() Event_functions.rocky_loot(event) @@ -62,6 +62,7 @@ end function Public.on_pre_player_left_game(event) local playertable = Chrono_table.get_player_table() local player = game.get_player(event.player_index) + if not player or not player.valid then return end if player.controller_type == defines.controllers.editor then player.toggle_map_editor() end @@ -74,6 +75,7 @@ function Public.on_player_joined_game(event) local objective = Chrono_table.get_table() local playertable = Chrono_table.get_player_table() local player = game.get_player(event.player_index) + if not player or not player.valid then return end if not playertable.flame_boots[event.player_index] then playertable.flame_boots[event.player_index] = {} end @@ -85,7 +87,7 @@ function Public.on_player_joined_game(event) local surface = game.surfaces[objective.active_surface_index] if player.online_time == 0 then - player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 32, 0.5), surface) + player.teleport(surface.find_non_colliding_position('character', player.force.get_spawn_position(surface), 32, 0.5) or {0, 0}, surface) for item, amount in pairs(Balance.starting_items) do player.insert({name = item, count = amount}) end @@ -95,16 +97,16 @@ function Public.on_player_joined_game(event) player.character = nil player.set_controller({type = defines.controllers.god}) player.create_character() - player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 32, 0.5), surface) + player.teleport(surface.find_non_colliding_position('character', player.force.get_spawn_position(surface), 32, 0.5) or {0, 0}, surface) for item, amount in pairs(Balance.starting_items) do player.insert({name = item, count = amount}) end end - local tile = surface.get_tile(player.position) + local tile = surface.get_tile(player.position.x, player.position.y) if tile.valid then if tile.name == 'out-of-map' then - player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 32, 0.5), surface) + player.teleport(surface.find_non_colliding_position('character', player.force.get_spawn_position(surface), 32, 0.5) or {0, 0}, surface) end end Minimap.update_surface(player) @@ -113,6 +115,7 @@ end function Public.on_player_changed_surface(event) local player = game.get_player(event.player_index) + if not player or not player.valid then return end Minimap.toggle_button(player) if not player.is_cursor_empty() then if player.cursor_stack and player.cursor_stack.valid_for_read then @@ -134,9 +137,54 @@ function Public.on_player_changed_surface(event) end +local function try_destroy_platform(entity, cause) + local pos = entity.position + local surface = entity.surface + if surface.platform then return end + local asteroids = { + ['small-metallic-asteroid'] = {size = 1, amount = 1}, + ['medium-metallic-asteroid'] = {size = 2, amount = 2}, + ['big-metallic-asteroid'] = {size = 3, amount = 4}, + ['huge-metallic-asteroid'] = {size = 6, amount = 6}, + ['small-carbonic-asteroid'] = {size = 1, amount = 1}, + ['medium-carbonic-asteroid'] = {size = 2, amount = 2}, + ['big-carbonic-asteroid'] = {size = 3, amount = 4}, + ['huge-carbonic-asteroid'] = {size = 6, amount = 6}, + ['small-oxide-asteroid'] = {size = 1, amount = 1}, + ['medium-oxide-asteroid'] = {size = 2, amount = 2}, + ['big-oxide-asteroid'] = {size = 3, amount = 4}, + ['huge-oxide-asteroid'] = {size = 6, amount = 6}, + ['small-interstellar-asteroid'] = {size = 1, amount = 1}, + ['medium-interstellar-asteroid'] = {size = 2, amount = 2}, + ['big-interstellar-asteroid'] = {size = 3, amount = 4}, + ['huge-interstellar-asteroid'] = {size = 6, amount = 6}, + } + local stone = asteroids[entity.name] + if cause then + for i = stone.amount, 0, -1 do + --register some loot or something. Can't spawn chunks outside the actual space platform! + end + return + end + local tiles = {} + local size = stone.size + for x = -size, size, 1 do + for y = -size, size, 1 do + local tile = entity.surface.get_tile(pos.x + x,pos.y + y) + if tile and tile.valid and tile.name == 'space-platform-foundation' then + tiles[#tiles+1] = {position = {x = pos.x + x, y = pos.y + y}, name = 'empty-space'} + end + end + end + entity.surface.set_tiles(tiles) +end + function Public.on_entity_died(event) local objective = Chrono_table.get_table() local entity = event.entity + if entity.type == 'asteroid' then + try_destroy_platform(entity, event.cause) + end if entity.type == 'tree' and objective.world.id == 4 then --choppy planet if event.cause then if event.cause.valid then @@ -248,9 +296,9 @@ function Public.on_built_entity(event) return end local objective = Chrono_table.get_table() - if entity.type == 'entity-ghost' then + --[[ if entity.type == 'entity-ghost' then entity.time_to_live = game.forces.player.ghost_time_to_live - end + end ]] if entity.name == 'spidertron' then if objective.world.id ~= 7 or entity.surface.name == 'cargo_wagon' then entity.destroy() @@ -263,6 +311,7 @@ end function Public.on_pre_player_died(event) local player = game.get_player(event.player_index) + if not player or not player.valid then return end local surface = player.surface local poisons = surface.count_entities_filtered {position = player.position, radius = 10, name = 'poison-cloud'} if poisons > 0 then @@ -277,7 +326,13 @@ end function Public.script_raised_revive(event) local entity = event.entity if not entity or not entity.valid then return end - if entity.force.name == "player" then return end + if entity.force.name == "player" then + entity.minable = false + entity.destructible = false + if entity.name == 'solar-panel' or entity.name == 'substation' then + entity.operable = false + end + end if entity.force.name == "scrapyard" then if entity.name == "gun-turret" then local objective = Chrono_table.get_table() diff --git a/maps/chronosphere/production.lua b/maps/chronosphere/production.lua index f136e989..d6af7efe 100644 --- a/maps/chronosphere/production.lua +++ b/maps/chronosphere/production.lua @@ -1,10 +1,10 @@ local Chrono_table = require 'maps.chronosphere.table' -local Rand = require 'maps.chronosphere.random' local Balance = require 'maps.chronosphere.balance' local Difficulty = require 'modules.difficulty_vote' local Public = {} local List = require 'maps.chronosphere.production_list' +local FT = require 'utils.functions.flying_texts' local function roll_assembler() local objective = Chrono_table.get_table() @@ -15,7 +15,7 @@ local function roll_assembler() table.insert(choices.weights, item.weight) end end - return Rand.raffle(choices.types, choices.weights) + return table.get_random_weighted_t(choices.types, choices.weights) end function Public.calculate_factory_level(xp, whole_level) @@ -53,13 +53,14 @@ local function produce(factory, train) factory.progress = factory.progress - (1 + multi) * List[id].base_time * 60 local inserted = factory.entity.get_output_inventory().insert {name = List[id].name, count = 1 + multi} factory.produced = factory.produced + inserted - factory.entity.surface.pollute(factory.entity.position, inserted * pollution_coef) + local surface = factory.entity.surface + surface.pollute(factory.entity.position, inserted * pollution_coef) if train then - game.pollution_statistics.on_flow('cargo-wagon', inserted * pollution_coef) - game.forces.player.item_production_statistics.on_flow(List[id].name, inserted) + game.get_pollution_statistics(surface).on_flow('cargo-wagon', inserted * pollution_coef) + game.forces.player.get_item_production_statistics(surface).on_flow(List[id].name, inserted) factory.entity.products_finished = factory.entity.products_finished + inserted else - game.pollution_statistics.on_flow('item-on-ground', inserted * pollution_coef) + game.get_pollution_statistics(surface).on_flow('item-on-ground', inserted * pollution_coef) end end end @@ -84,17 +85,6 @@ local function levelup_train_factory(id) production.train_assemblers[id].tier = level end -local function flying_text(surface, position, text, color) - surface.create_entity( - { - name = 'flying-text', - position = {position.x, position.y - 0.5}, - text = text, - color = color - } - ) -end - function Public.produce_assemblers() local production = Chrono_table.get_production_table() for _, factory in pairs(production.assemblers) do @@ -159,10 +149,10 @@ function Public.check_activity() local count = surface.count_entities_filtered {position = entity.position, radius = 10, force = 'player'} if count > 10 then factory.active = true - flying_text(surface, entity.position, 'Active', {r = 0, g = 0.98, b = 0}) + FT.flying_text(nil, surface, entity.position, 'Active', {r = 0, g = 0.98, b = 0}) else factory.active = false - flying_text(surface, entity.position, 'Not Active', {r = 0.98, g = 0, b = 0}) + FT.flying_text(nil, surface, entity.position, 'Not Active', {r = 0.98, g = 0, b = 0}) end ::continue:: end diff --git a/maps/chronosphere/production_list.lua b/maps/chronosphere/production_list.lua index 9def395a..31e8fc6f 100644 --- a/maps/chronosphere/production_list.lua +++ b/maps/chronosphere/production_list.lua @@ -44,7 +44,7 @@ List[6] = { id = 6, jump_min = 6, name = 'light-oil-barrel', - recipe_override = 'fill-light-oil-barrel', + recipe_override = 'light-oil-barrel', kind = 'fluid-assembler', base_time = 8, weight = 3 @@ -60,7 +60,7 @@ List[7] = { List[8] = { id = 8, jump_min = 4, - name = 'empty-barrel', + name = 'barrel', kind = 'assembler', base_time = 10, weight = 3 diff --git a/maps/chronosphere/raffles.lua b/maps/chronosphere/raffles.lua index dec286df..15753c54 100644 --- a/maps/chronosphere/raffles.lua +++ b/maps/chronosphere/raffles.lua @@ -12,27 +12,27 @@ Public.biters = { } Public.rocks = { - 'sand-rock-big', - 'sand-rock-big', - 'rock-big', - 'rock-big', - 'rock-big', - 'rock-big', - 'rock-big', - 'rock-big', - 'rock-big', - 'rock-huge' + 'big-sand-rock', + 'big-sand-rock', + 'big-rock', + 'big-rock', + 'big-rock', + 'big-rock', + 'big-rock', + 'big-rock', + 'big-rock', + 'huge-rock' } Public.rock_decoratives = { - 'rock-medium', - 'rock-small', - 'rock-small', - 'rock-tiny', - 'rock-tiny', - 'rock-tiny', - 'sand-rock-medium', - 'sand-rock-small' + 'medium-rock', + 'small-rock', + 'small-rock', + 'tiny-rock', + 'tiny-rock', + 'tiny-rock', + 'medium-sand-rock', + 'small-sand-rock' } Public.ores = { diff --git a/maps/chronosphere/random.lua b/maps/chronosphere/random.lua deleted file mode 100644 index 3fcb7b40..00000000 --- a/maps/chronosphere/random.lua +++ /dev/null @@ -1,73 +0,0 @@ -local math_random = math.random -local Public = {} - -function Public.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 function is_closer(pos1, pos2, pos) - return ((pos1.x - pos.x) ^ 2 + (pos1.y - pos.y) ^ 2) < ((pos2.x - pos.x) ^ 2 + (pos2.y - pos.y) ^ 2) -end - -function Public.shuffle_distance(tbl, position) - local size = #tbl - for i = size, 1, -1 do - local rand = math_random(size) - if is_closer(tbl[i].position, tbl[rand].position, position) and i > rand then - tbl[i], tbl[rand] = tbl[rand], tbl[i] - end - end - return tbl -end - -function Public.raffle(values, weights) --arguments of the form {[a] = A, [b] = B, ...} and {[a] = a_weight, [b] = b_weight, ...} or just {a,b,c,...} and {1,2,3...} - local total_weight = 0 - for k, w in pairs(weights) do - assert(values[k]) - if w > 0 then - total_weight = total_weight + w - end - -- negative weights treated as zero - end - assert(total_weight > 0) - - local cumulative_probability = 0 - local rng = math_random() - for k, v in pairs(values) do - assert(weights[k]) - cumulative_probability = cumulative_probability + (weights[k] / total_weight) - if rng <= cumulative_probability then - return v - end - end -end - -function Public.spairs(t, order) - -- collect the keys - local keys = {} - for k in pairs(t) do keys[#keys+1] = k end - - -- if order function given, sort by it by passing the table and keys a, b, - -- otherwise just sort the keys - if order then - table.sort(keys, function(a,b) return order(t, a, b) end) - else - table.sort(keys) - end - - -- return the iterator function - local i = 0 - return function() - i = i + 1 - if keys[i] then - return keys[i], t[keys[i]] - end - end -end - -return Public diff --git a/maps/chronosphere/table.lua b/maps/chronosphere/table.lua index 3e192dd8..1337ad62 100644 --- a/maps/chronosphere/table.lua +++ b/maps/chronosphere/table.lua @@ -132,7 +132,7 @@ function Public.reset_table() chronosphere.research_tokens.tech = 0 chronosphere.research_tokens.ecology = 0 chronosphere.research_tokens.weapons = 0 - chronosphere.laser_battery = 0 + chronosphere.laser_battery = nil chronosphere.last_artillery_event = 0 chronosphere.poison_mastery_unlocked = 0 chronosphere.gen_speed = 2 diff --git a/maps/chronosphere/terrain_specials.lua b/maps/chronosphere/terrain_specials.lua index 4ee39af9..96c6b0d8 100644 --- a/maps/chronosphere/terrain_specials.lua +++ b/maps/chronosphere/terrain_specials.lua @@ -22,8 +22,11 @@ function Public.danger_event(surface, left_top) rendering.draw_text { text = 'Nuclear silo', surface = surface, - target = pole, - target_offset = {5, -2.5}, + target = { + entity = pole, + offset = {5, -2.5}, + position = pole.position + }, color = {r = 0.98, g = 0, b = 0}, scale = 1.00, font = 'default-game', @@ -35,17 +38,20 @@ function Public.danger_event(surface, left_top) rendering.draw_text { text = ' ', surface = surface, - target = pole, - target_offset = {5, -1.5}, + target = { + entity = pole, + offset = {5, -1.5}, + position = pole.position + }, color = {r = 0.98, g = 0, b = 0}, scale = 1.00, font = 'default-game', alignment = 'center', scale_with_zoom = false } - silo.get_module_inventory().insert('effectivity-module-3') + silo.get_module_inventory().insert('efficiency-module-3') silo.rocket_parts = 100 - --silo.get_module_inventory().insert("effectivity-module-3") + --silo.get_module_inventory().insert("efficiency-module-3") local combinator = surface.create_entity({name = 'constant-combinator', position = {x = left_top.x + 11, y = left_top.y + 10}, force = 'player', create_build_effect_smoke = false}) local speaker = @@ -59,7 +65,7 @@ function Public.danger_event(surface, left_top) alert_parameters = {show_alert = true, show_on_map = true, icon_signal_id = {type = 'item', name = 'atomic-bomb'}, alert_message = 'Nuclear missile silo detected!'} } ) - combinator.connect_neighbour({wire = defines.wire_type.green, target_entity = speaker}) + combinator.get_wire_connector(defines.wire_connector_id.circuit_green, true).connect_to(speaker.get_wire_connector(defines.wire_connector_id.circuit_green, true), false) local rules = combinator.get_or_create_control_behavior() local rules2 = speaker.get_or_create_control_behavior() rules.set_signal(1, {signal = {type = 'virtual', name = 'signal-A'}, count = 1}) @@ -100,8 +106,11 @@ function Public.fish_market(surface, left_top) rendering.draw_text { text = 'Fish Market', surface = surface, - target = market, - target_offset = {0, -2.5}, + target = { + entity = market, + offset = {0, -2.5}, + position = market.position + }, color = objective.locomotive.color, scale = 1.00, font = 'default-game', @@ -116,8 +125,11 @@ function Public.fish_market(surface, left_top) rendering.draw_text { text = 'Deposit fish here', surface = surface, - target = fishchest, - target_offset = {0, -2.5}, + target = { + entity = fishchest, + offset = {0, -2.5}, + position = fishchest.position + }, color = objective.locomotive.color, scale = 0.75, font = 'default-game', diff --git a/maps/chronosphere/tick_functions.lua b/maps/chronosphere/tick_functions.lua index ee530bfb..78f01296 100644 --- a/maps/chronosphere/tick_functions.lua +++ b/maps/chronosphere/tick_functions.lua @@ -79,8 +79,9 @@ function Public.train_pollution(source, interior_pollution) elseif source == 'wagons' then pollution = interior_pollution * Balance.machine_pollution_transfer_from_inside_factor(difficulty, objective.upgrades[2]) end - game.surfaces[objective.active_surface_index].pollute(pos, pollution) - game.pollution_statistics.on_flow(stat_target, pollution - interior_pollution) + local surface = game.surfaces[objective.active_surface_index] + surface.pollute(pos, pollution) + game.get_pollution_statistics(surface).on_flow(stat_target, pollution - interior_pollution) end function Public.transfer_pollution() @@ -101,12 +102,12 @@ function Public.ramp_evolution() objective.passivetimer * objective.passive_chronocharge_rate > objective.chronochargesneeded * 0.50 and objective.chronojumps >= Balance.jumps_until_overstay_is_on(Difficulty.get().difficulty_vote_value) then - local evolution = game.forces.enemy.evolution_factor + local evolution = game.forces.enemy.get_evolution_factor(game.get_surface(objective.active_surface_index)) evolution = evolution * Balance.evoramp50_multiplier_per_10s(difficulty) if evolution > 1 then evolution = 1 end - game.forces.enemy.evolution_factor = evolution + game.forces.enemy.set_evolution_factor(evolution, game.get_surface(objective.active_surface_index)) end end @@ -327,7 +328,7 @@ function Public.dangertimer() objective.dangers[i].silo.launch_rocket() objective.dangers[i].silo.rocket_parts = 100 end - rendering.set_text(objective.dangers[i].timer, math_floor(timer / 60) .. ' min, ' .. timer % 60 .. ' s') + objective.dangers[i].timer.text = math_floor(timer / 60) .. ' min, ' .. timer % 60 .. ' s' end end end @@ -372,7 +373,7 @@ function Public.offline_players() player_inv[4] = game.players[players[i].index].get_inventory(defines.inventory.character_ammo) player_inv[5] = game.players[players[i].index].get_inventory(defines.inventory.character_trash) local e = surface.create_entity({name = 'character', position = game.forces.player.get_spawn_position(surface), force = 'neutral'}) - local inv = e.get_inventory(defines.inventory.character_main) + local inv = e and e.get_inventory(defines.inventory.character_main) for ii = 1, 5, 1 do if player_inv[ii].valid then for iii = 1, #player_inv[ii], 1 do @@ -384,14 +385,18 @@ function Public.offline_players() end if #items > 0 then for item = 1, #items, 1 do - if items[item].valid then + if items[item].valid and inv and inv.valid then inv.insert(items[item]) end end game.print({'chronosphere.message_accident'}, {r = 0.98, g = 0.66, b = 0.22}) - e.die('neutral') + if e and e.valid then + e.die('neutral') + end else - e.destroy() + if e and e.valid then + e.destroy() + end end for ii = 1, 5, 1 do @@ -512,7 +517,7 @@ function Public.giftmas_lights() [4] = {r = 63, g = 49, b = 255, a = 1}, --modrĂ¡ } for _ = 1, 5, 1 do - rendering.set_color(lights[math_random(1, nr)], colors[math_random(1, 4)]) + lights[math_random(1, nr)].color = colors[math_random(1, 4)] end end diff --git a/maps/chronosphere/treasure.lua b/maps/chronosphere/treasure.lua index d310b839..f330a6b6 100644 --- a/maps/chronosphere/treasure.lua +++ b/maps/chronosphere/treasure.lua @@ -1,5 +1,4 @@ local Chrono_table = require 'maps.chronosphere.table' -local Rand = require 'maps.chronosphere.random' local Balance = require 'maps.chronosphere.balance' local Difficulty = require 'modules.difficulty_vote' local math_random = math.random @@ -36,8 +35,8 @@ local function treasure_chest_loot(difficulty, world) {3, 0, 1, false, 'small-lamp', 8, 32}, {2, 0, 1, false, 'electric-mining-drill', 2, 4}, {3, 0, 1, false, 'long-handed-inserter', 4, 16}, - {0.5, 0, 1, false, 'filter-inserter', 2, 12}, - {0.2, 0, 1, false, 'stack-filter-inserter', 2, 6}, + --{0.5, 0, 1, false, 'filter-inserter', 2, 12}, + --{0.2, 0, 1, false, 'stack-filter-inserter', 2, 6}, {0.2, 0, 1, false, 'slowdown-capsule', 2, 4}, {0.2, 0, 1, false, 'destroyer-capsule', 2, 4}, {0.2, 0, 1, false, 'defender-capsule', 2, 4}, @@ -47,7 +46,7 @@ local function treasure_chest_loot(difficulty, world) {1, 0.15, 1, false, 'pump', 1, 2}, {2, 0.15, 1, false, 'pumpjack', 1, 3}, {0.02, 0.15, 1, false, 'oil-refinery', 1, 2}, - {3, 0, 1, false, 'effectivity-module', 1, 4}, + {3, 0, 1, false, 'efficiency-module', 1, 4}, {3, 0, 1, false, 'speed-module', 1, 4}, {3, 0, 1, false, 'productivity-module', 1, 4}, --shotgun meta: @@ -149,7 +148,7 @@ local function treasure_chest_loot(difficulty, world) -- super late-game: --{9, 0.8, 1.2, false, "railgun-dart", 12, 20}, {1, 0.9, 1.1, true, 'power-armor-mk2', 1, 1}, - {1, 0.8, 1.2, true, 'fusion-reactor-equipment', 1, 1} + {1, 0.8, 1.2, true, 'fission-reactor-equipment', 1, 1} --{2, 0, 1, , "computer", 1, 1}, --{1, 0.2, 1, , "railgun", 1, 1}, @@ -178,7 +177,7 @@ local function treasure_chest_loot(difficulty, world) {2, 0.2, 1.6, true, 'nuclear-reactor', 1, 1}, {2, 0.2, 1, false, 'centrifuge', 1, 1}, {1, 0.25, 1.75, true, 'nuclear-fuel', 1, 1}, - {1, 0.5, 1.5, true, 'fusion-reactor-equipment', 1, 1}, + {1, 0.5, 1.5, true, 'fission-reactor-equipment', 1, 1}, {1, 0.5, 1.5, true, 'atomic-bomb', 1, 1} } end @@ -186,14 +185,14 @@ local function treasure_chest_loot(difficulty, world) --[[ if world.id == 7 then --biterwrld specialised_loot_raw = { - {4, 0, 1, false, "effectivity-module", 1, 4}, + {4, 0, 1, false, "efficiency-module", 1, 4}, {4, 0, 1, false, "productivity-module", 1, 4}, {4, 0, 1, false, "speed-module", 1, 4}, {2, 0, 1, false, "beacon", 1, 1}, - {0.5, 0, 1, false, "effectivity-module-2", 1, 4}, + {0.5, 0, 1, false, "efficiency-module-2", 1, 4}, {0.5, 0, 1, false, "productivity-module-2", 1, 4}, {0.5, 0, 1, false, "speed-module-2", 1, 4}, - {0.1, 0, 1, false, "effectivity-module-3", 1, 4}, + {0.1, 0, 1, false, "efficiency-module-3", 1, 4}, {0.1, 0, 1, false, "productivity-module-3", 1, 4}, {0.1, 0, 1, false, "speed-module-3", 1, 4}, @@ -321,7 +320,7 @@ function Public.treasure_chest(surface, position, container_name) e.minable = false local inv = e.get_inventory(defines.inventory.chest) for _ = 1, math_random(2, 6), 1 do - local loot = Rand.raffle(loot_types, loot_weights) + local loot = table.get_random_weighted_t(loot_types, loot_weights) local difficulty_scaling = Balance.treasure_quantity_difficulty_scaling(difficulty) if objective.chronojumps == 0 then difficulty_scaling = 1 diff --git a/maps/chronosphere/upgrade_list.lua b/maps/chronosphere/upgrade_list.lua index b253bf04..0b11ee15 100644 --- a/maps/chronosphere/upgrade_list.lua +++ b/maps/chronosphere/upgrade_list.lua @@ -77,7 +77,7 @@ function Public.upgrade2(coin_scaling) local difficulty = Difficulty.get().difficulty_vote_value local upgrade = { name = {'chronosphere.upgrade_filter'}, - sprite = 'recipe/effectivity-module', + sprite = 'recipe/efficiency-module', max_level = 9, type = 'train', enabled = true, @@ -182,9 +182,9 @@ function Public.upgrade5(coin_scaling) item3 = {name = 'iron-chest', tt = 'entity-name', sprite = 'item/iron-chest', count = math_max(0, 250 - math_abs(objective.upgrades[5] - 1) * 250)}, item4 = {name = 'steel-chest', tt = 'entity-name', sprite = 'item/steel-chest', count = math_max(0, 250 - math_abs(objective.upgrades[5] - 2) * 250)}, item5 = { - name = 'logistic-chest-storage', + name = 'storage-chest', tt = 'entity-name', - sprite = 'item/logistic-chest-storage', + sprite = 'item/storage-chest', count = math_max(0, 250 - math_abs(objective.upgrades[5] - 3) * 250) } }, @@ -267,7 +267,7 @@ function Public.upgrade9(coin_scaling) local objective = Chrono_table.get_table() local upgrade = { name = {'chronosphere.upgrade_storage'}, - sprite = 'item/logistic-chest-storage', + sprite = 'item/storage-chest', max_level = 4, type = 'train', enabled = true, @@ -285,9 +285,9 @@ function Public.upgrade9(coin_scaling) item3 = {name = 'iron-chest', tt = 'entity-name', sprite = 'item/iron-chest', count = math_max(0, 250 - math_abs(objective.upgrades[9] - 1) * 250)}, item4 = {name = 'steel-chest', tt = 'entity-name', sprite = 'item/steel-chest', count = math_max(0, 250 - math_abs(objective.upgrades[9] - 2) * 250)}, item5 = { - name = 'logistic-chest-storage', + name = 'storage-chest', tt = 'entity-name', - sprite = 'item/logistic-chest-storage', + sprite = 'item/storage-chest', count = math_max(0, 250 - math_abs(objective.upgrades[9] - 3) * 250) } }, @@ -318,10 +318,10 @@ function Public.upgrade10(coin_scaling) return upgrade end -function Public.upgrade11() +function Public.upgrade11(_coin_scaling) local upgrade = { name = {'chronosphere.upgrade_fusion'}, - sprite = 'recipe/fusion-reactor-equipment', + sprite = 'recipe/fission-reactor-equipment', max_level = 999, type = 'player', enabled = true, @@ -340,7 +340,7 @@ function Public.upgrade11() return upgrade end -function Public.upgrade12() +function Public.upgrade12(_coin_scaling) local upgrade = { name = {'chronosphere.upgrade_mk2'}, sprite = 'recipe/power-armor-mk2', @@ -410,7 +410,7 @@ function Public.upgrade15(coin_scaling) local objective = Chrono_table.get_table() local upgrade = { name = {'chronosphere.upgrade_computer3'}, - sprite = 'item/rocket-control-unit', + sprite = 'item/utility-science-pack', max_level = 10, type = 'quest', enabled = objective.upgrades[14] == 1, @@ -420,7 +420,7 @@ function Public.upgrade15(coin_scaling) cost = { item1 = {name = 'coin', tt = 'item-name', sprite = 'item/coin', count = 2000 * coin_scaling}, item2 = {name = 'low-density-structure', tt = 'item-name', sprite = 'item/low-density-structure', count = 100}, - item3 = {name = 'rocket-control-unit', tt = 'item-name', sprite = 'item/rocket-control-unit', count = 100}, + item3 = {name = 'utility-science-pack', tt = 'item-name', sprite = 'item/utility-science-pack', count = 100}, item4 = {name = 'uranium-fuel-cell', tt = 'item-name', sprite = 'item/uranium-fuel-cell', count = 50} }, virtual_cost = { @@ -430,11 +430,11 @@ function Public.upgrade15(coin_scaling) return upgrade end -function Public.upgrade16() +function Public.upgrade16(_coin_scaling) local objective = Chrono_table.get_table() local upgrade = { name = {'chronosphere.upgrade_computer4'}, - sprite = 'item/satellite', + sprite = 'item/space-science-pack', max_level = 1, type = 'quest', enabled = objective.upgrades[15] == 10, @@ -443,7 +443,7 @@ function Public.upgrade16() jump_limit = 25, cost = { item1 = {name = 'rocket-silo', tt = 'entity-name', sprite = 'item/rocket-silo', count = 1}, - item2 = {name = 'satellite', tt = 'item-name', sprite = 'item/satellite', count = 1}, + item2 = {name = 'space-science-pack', tt = 'item-name', sprite = 'item/space-science-pack', count = 1}, item3 = {name = 'spidertron', tt = 'entity-name', sprite = 'item/spidertron', count = 2} }, virtual_cost = { @@ -476,7 +476,7 @@ function Public.upgrade17(coin_scaling) return upgrade end -function Public.upgrade18() +function Public.upgrade18(_coin_scaling) local objective = Chrono_table.get_table() local upgrade = { name = {'chronosphere.upgrade_researchspeed'}, @@ -562,7 +562,7 @@ function Public.upgrade20(coin_scaling) return upgrade end -function Public.upgrade21() +function Public.upgrade21(_coin_scaling) local objective = Chrono_table.get_table() local difficulty = Difficulty.get().difficulty_vote_value local upgrade = { @@ -634,8 +634,8 @@ function Public.upgrade23(coin_scaling) item2 = {name = 'artillery-turret', tt = 'entity-name', sprite = 'item/artillery-turret', count = 10}, item3 = {name = 'military-science-pack', tt = 'item-name', sprite = 'item/military-science-pack', count = 1000}, item4 = {name = 'atomic-bomb', tt = 'item-name', sprite = 'item/atomic-bomb', count = 20}, - item5 = {name = 'rocket-control-unit', tt = 'item-name', sprite = 'item/rocket-control-unit', count = 50}, - item6 = {name = 'satellite', tt = 'item-name', sprite = 'item/satellite', count = 1} + item5 = {name = 'utility-science-pack', tt = 'item-name', sprite = 'item/utility-science-pack', count = 50}, + item6 = {name = 'space-science-pack', tt = 'item-name', sprite = 'item/space-science-pack', count = 1} }, virtual_cost = { virtual1 = {type = 'tech', name = Public.tokens.tech.name, tt = 'chronosphere', sprite = Public.tokens.tech.sprite, count = 200} @@ -644,7 +644,7 @@ function Public.upgrade23(coin_scaling) return upgrade end -function Public.upgrade24() +function Public.upgrade24(_coin_scaling) local objective = Chrono_table.get_table() local upgrade = { name = {'chronosphere.upgrade_nuclear_artillery_ammo'}, @@ -665,7 +665,7 @@ function Public.upgrade24() return upgrade end -function Public.upgrade25() +function Public.upgrade25(_coin_scaling) local objective = Chrono_table.get_table() local upgrade = { name = {'chronosphere.upgrade_poison_mastery'}, diff --git a/maps/chronosphere/upgrades.lua b/maps/chronosphere/upgrades.lua index b1be57e6..b50c2d98 100644 --- a/maps/chronosphere/upgrades.lua +++ b/maps/chronosphere/upgrades.lua @@ -36,7 +36,7 @@ end local function upgrade_hp() local objective = Chrono_table.get_table() objective.max_health = 10000 + 2500 * objective.upgrades[1] - rendering.set_text(objective.health_text, 'HP: ' .. objective.health .. ' / ' .. objective.max_health) + objective.health_text.text = 'HP: ' .. objective.health .. ' / ' .. objective.max_health end local function spawn_accumulators() @@ -90,14 +90,18 @@ local function upgrade_out() local positions = {{-16, -62}, {15, -62}, {-16, 66}, {15, 66}} for i = 1, 4, 1 do local e = game.surfaces['cargo_wagon'].create_entity({name = 'blue-chest', position = positions[i], force = 'player'}) + if not e or not e.valid then break end e.destructible = false e.minable = false objective.outchests[i] = e rendering.draw_text { text = 'Output', surface = e.surface, - target = e, - target_offset = {0, -1.5}, + target = { + entity = e, + offset = {0, -1.5}, + position = e.position + }, color = objective.locomotive.color, scale = 0.80, font = 'default-game', diff --git a/maps/chronosphere/world_functions.lua b/maps/chronosphere/world_functions.lua index 04aea098..cb019641 100644 --- a/maps/chronosphere/world_functions.lua +++ b/maps/chronosphere/world_functions.lua @@ -70,7 +70,7 @@ local function get_replacement_tile(surface, position) table.shuffle_table(vectors) for k, v in pairs(vectors) do local tile = surface.get_tile(position.x + v[1], position.y + v[2]) - if not tile.collides_with('resource') then + if tile and tile.valid and not tile.collides_with('resource') then return tile.name end end @@ -97,7 +97,7 @@ function Public.replace_water(surface, left_top) local p = { x = left_top.x + x, y = left_top.y + y } local tile = surface.get_tile(p) if tile.hidden_tile then - surface.set_hidden_tile(p, get_replacement_tile(surface, p).name) + surface.set_hidden_tile(p, get_replacement_tile(surface, p)) elseif tile.collides_with('resource') then tiles[#tiles + 1] = { name = get_replacement_tile(surface, p), position = p } end @@ -220,15 +220,16 @@ function Public.process_labyrinth_cell(pos, seed) end function Public.build_blueprint(surface, position, id, force) - local item = surface.create_entity { name = "item-on-ground", position = position, stack = { name = "blueprint", count = 1 } } - local success = item.stack.import_stack(Blueprints[id]) + local nauvis = game.get_surface(1) + local item = nauvis and nauvis.create_entity { name = "item-on-ground", position = position, stack = { name = "blueprint", count = 1 } } + local success = item and item.stack.import_stack(Blueprints[id]) if success <= 0 then - local ghosts = item.stack.build_blueprint { surface = surface, force = force, position = position, build_mode = defines.build_mode.forced } + local ghosts = item and item.stack.build_blueprint { surface = surface, force = force, position = position, build_mode = defines.build_mode.forced } or {} for _, ghost in pairs(ghosts) do ghost.silent_revive({ raise_revive = true }) end end - if item.valid then item.destroy() end + if item and item.valid then item.destroy() end end return Public diff --git a/maps/chronosphere/world_list.lua b/maps/chronosphere/world_list.lua index 25c4b43f..7f4232cf 100644 --- a/maps/chronosphere/world_list.lua +++ b/maps/chronosphere/world_list.lua @@ -1,7 +1,6 @@ local Chrono_table = require 'maps.chronosphere.table' local Balance = require 'maps.chronosphere.balance' local Difficulty = require 'modules.difficulty_vote' -local Rand = require 'maps.chronosphere.random' local random = math.random local Public = {} local Worlds = {} @@ -10,17 +9,18 @@ Worlds[1] = { world_id = 1, map = require 'maps.chronosphere.worlds.basic', variants = { - [1] = {id = 1, min = 1, weight = 1, name = {'chronosphere.map_1_1'}, fe = 6, cu = 1, c = 1, s = 1, u = 0, o = 1, biters = 16, moisture = -0.2, fa = 1}, - [2] = {id = 2, min = 1, weight = 1, name = {'chronosphere.map_1_2'}, fe = 1, cu = 6, c = 1, s = 1, u = 0, o = 1, biters = 16, moisture = 0.2, fa = 1}, - [3] = {id = 3, min = 2, weight = 1, name = {'chronosphere.map_1_3'}, fe = 1, cu = 1, c = 1, s = 6, u = 0, o = 1, biters = 16, moisture = -0.2, fa = 1}, - [4] = {id = 4, min = 4, weight = 1, name = {'chronosphere.map_1_4'}, fe = 1, cu = 1, c = 1, s = 1, u = 0, o = 6, biters = 16, moisture = 0.1, fa = 1}, - [5] = {id = 5, min = 6, weight = 1, name = {'chronosphere.map_1_5'}, fe = 1, cu = 1, c = 1, s = 1, u = 6, o = 1, biters = 16, moisture = -0.2, fa = 1}, - [6] = {id = 6, min = 2, weight = 1, name = {'chronosphere.map_1_6'}, fe = 1, cu = 1, c = 6, s = 1, u = 0, o = 1, biters = 16, moisture = 0, fa = 1}, - [7] = {id = 7, min = 4, weight = 1, name = {'chronosphere.map_1_7'}, fe = 2, cu = 2, c = 2, s = 2, u = 4, o = 3, biters = 40, moisture = 0.2, fa = 0}, - [8] = {id = 8, min = 2, weight = 1, name = {'chronosphere.map_1_8'}, fe = 1, cu = 1, c = 1, s = 1, u = 0, o = 0, biters = 16, moisture = 0.1, fa = 4}, - [9] = {id = 9, min = 1, weight = 1, name = {'chronosphere.map_1_9'}, fe = 2, cu = 2, c = 2, s = 2, u = 0, o = 2, biters = 10, moisture = 0, fa = 1}, - [10] = {id = 10, min = 0, weight = 0, name = {'chronosphere.map_1_10'}, fe = 4, cu = 3, c = 4, s = 2, u = 0, o = 0, biters = 1, moisture = -0.3, fa = 0}, - [11] = {id = 11, min = 6, weight = 1, name = {'chronosphere.map_1_11'}, fe = 3, cu = 3, c = 2, s = 3, u = 0, o = 0, biters = 6, moisture = -0.5, fa = 4} + [1] = {id = 1, min = 1, weight = 1, name = {'chronosphere.map_1_1'}, pl = 'nauvis', fe = 6, cu = 1, c = 1, s = 1, u = 0, o = 1, biters = 16, moisture = -0.2, fa = 1}, + [2] = {id = 2, min = 1, weight = 1, name = {'chronosphere.map_1_2'}, pl = 'nauvis',fe = 1, cu = 6, c = 1, s = 1, u = 0, o = 1, biters = 16, moisture = 0.2, fa = 1}, + [3] = {id = 3, min = 2, weight = 1, name = {'chronosphere.map_1_3'}, pl = 'nauvis',fe = 1, cu = 1, c = 1, s = 6, u = 0, o = 1, biters = 16, moisture = -0.2, fa = 1}, + [4] = {id = 4, min = 4, weight = 1, name = {'chronosphere.map_1_4'}, pl = 'nauvis',fe = 1, cu = 1, c = 1, s = 1, u = 0, o = 6, biters = 16, moisture = 0.1, fa = 1}, + [5] = {id = 5, min = 6, weight = 1, name = {'chronosphere.map_1_5'}, pl = 'nauvis',fe = 1, cu = 1, c = 1, s = 1, u = 6, o = 1, biters = 16, moisture = -0.2, fa = 1}, + [6] = {id = 6, min = 2, weight = 1, name = {'chronosphere.map_1_6'}, pl = 'nauvis',fe = 1, cu = 1, c = 6, s = 1, u = 0, o = 1, biters = 16, moisture = 0, fa = 1}, + [7] = {id = 7, min = 4, weight = 1, name = {'chronosphere.map_1_7'}, pl = 'nauvis',fe = 2, cu = 2, c = 2, s = 2, u = 4, o = 3, biters = 40, moisture = 0.2, fa = 0}, + [8] = {id = 8, min = 2, weight = 1, name = {'chronosphere.map_1_8'}, pl = 'nauvis',fe = 1, cu = 1, c = 1, s = 1, u = 0, o = 0, biters = 16, moisture = 0.1, fa = 4}, + [9] = {id = 9, min = 1, weight = 1, name = {'chronosphere.map_1_9'}, pl = 'nauvis',fe = 2, cu = 2, c = 2, s = 2, u = 0, o = 2, biters = 10, moisture = 0, fa = 1}, + [10] = {id = 10, min = 0, weight = 0, name = {'chronosphere.map_1_10'}, pl = 'nauvis',fe = 4, cu = 3, c = 4, s = 2, u = 0, o = 0, biters = 1, moisture = -0.3, fa = 0}, + [11] = {id = 11, min = 6, weight = 1, name = {'chronosphere.map_1_11'}, pl = 'nauvis',fe = 3, cu = 3, c = 2, s = 3, u = 0, o = 0, biters = 6, moisture = -0.5, fa = 4}, + --[12] = {id = 12, min = 1, weight = 100, name = {'chronosphere.map_1_11'}, pl = 'vulcanus',fe = 3, cu = 3, c = 2, s = 3, u = 0, o = 0, biters = 0, moisture = -0.5, fa = 4} }, modifiers = {}, default_tile = 'grass-1' @@ -173,10 +173,11 @@ end function Public.determine_world(optional_choice) local objective = Chrono_table.get_table() local difficulty = Difficulty.get().difficulty_vote_value + local SA = script.active_mods['space-travel'] local chosen_id local chosen_variant_id - local ores = Rand.raffle(ore_richness_variants, Balance.ore_richness_weights(difficulty)) - local dayspeed = Rand.raffle(time_speed_variants, time_speed_weights) + local ores = table.get_random_weighted_t(ore_richness_variants, Balance.ore_richness_weights(difficulty)) + local dayspeed = table.get_random_weighted_t(time_speed_variants, time_speed_weights) local daytime = random(0, 100) / 100 local special = special_world() if special.yes then @@ -195,6 +196,7 @@ function Public.determine_world(optional_choice) id = chosen_id, variant = Worlds[chosen_id].variants[chosen_variant_id], default_tile = Worlds[chosen_id].default_tile or 'grass-1', + planet_name = SA and Worlds[chosen_id].variants[chosen_variant_id].pl or 'nauvis', ores = ores, dayspeed = dayspeed, daytime = daytime @@ -217,7 +219,7 @@ function Public.determine_world(optional_choice) if Worlds[tonumber(optional_choice)] then chosen_id = tonumber(optional_choice) else - chosen_id = Rand.raffle(choices.types, choices.weights) + chosen_id = table.get_random_weighted_t(choices.types, choices.weights) end local variant_choices = {types = {}, weights = {}} for _, variant in pairs(Worlds[chosen_id].variants) do @@ -230,7 +232,7 @@ function Public.determine_world(optional_choice) optional_choice = nil goto retry end - chosen_variant_id = Rand.raffle(variant_choices.types, variant_choices.weights) + chosen_variant_id = table.get_random_weighted_t(variant_choices.types, variant_choices.weights) local modifiers = get_modifiers(chosen_id) if modifiers.ores then ores = modifiers.ores @@ -251,6 +253,7 @@ function Public.determine_world(optional_choice) id = chosen_id, variant = Worlds[chosen_id].variants[chosen_variant_id], default_tile = Worlds[chosen_id].default_tile, + planet_name = SA and Worlds[chosen_id].variants[chosen_variant_id].pl or 'nauvis', ores = ores, dayspeed = dayspeed, daytime = daytime diff --git a/maps/chronosphere/worlds/basic.lua b/maps/chronosphere/worlds/basic.lua index ecf4b6a6..b23dcdea 100644 --- a/maps/chronosphere/worlds/basic.lua +++ b/maps/chronosphere/worlds/basic.lua @@ -55,7 +55,7 @@ local function process_tile(p, seed, entities, treasure, factories) if roll == 1 then entities[#entities + 1] = {name = Raffle.spawners[random(1, #Raffle.spawners)], position = p, spawn_decorations = true} elseif roll == 2 then - local evo = game.forces['enemy'].evolution_factor + local evo = game.forces.enemy.get_evolution_factor(game.get_surface(objective.active_surface_index)) entities[#entities + 1] = {name = Raffle.worms[random(1 + floor(evo * 8), floor(1 + evo * 16))], position = p, spawn_decorations = true} elseif roll == 3 then if random(1, 50) == 1 then diff --git a/maps/chronosphere/worlds/blueprints.lua b/maps/chronosphere/worlds/blueprints.lua index b4b9ae1b..39c095f9 100644 --- a/maps/chronosphere/worlds/blueprints.lua +++ b/maps/chronosphere/worlds/blueprints.lua @@ -1,4 +1,6 @@ local Public = {} +--[[top of locomotive]] +Public[1] = '0eNrlnEGPozYUgP/K1teSFTaQQA6Vunvae2/VCBniSawFGxlIG43y32uTySQzIc17457qy2gC+PH84Uf8OQkvpGpG0RmpBrJ+IbLWqifrP19IL7eKN27bcOgEWRM5iJZERPHWveJ1PbZjwwdtyDEiUm3E32RNj08REWqQgxSnMNOLQ6nGthLGHnAJYOSwa8Ug60Wt20qqKVREOt3b1lq5M9uIi2T5NYvIwf7HstieySY4GN2UldjxvbRN7HGXWKXdvZna927HszT9UN50ZS/NMNotb8mcjlj87rrSCxfDBeoH7qjEEdGdMPyUFfnVNtPj0I24wMdT7krUb9lR92drhFDXqOTGYrKcamnqUQ7Ta3Z8ss3Z3eMT9v54ex3cCW/wMzz+1f8A/zcsfobDnwLxJ3j8aYijP0GO/hSGP8Xjz0LEnyLxUxj+DI+fhYg/Q+JfwvAv8fiTEPEvkfgTGP4VHn8cIv4VEn8Ow5/j8dMQ8edI/BkMf4HGz/IQ8RfIiWcMw09jPP8iQP4sRg7/FZC/l/emeTD8kd4LnHlSL+8NCD/Se4HaS728NyD8WO8F4vfy3oDwI70XuOpAvbw3IPxI7wXOPKmX9waEH+m9wFUH6uW9AeFHei904unlvQHhR3ovcNWBenlvQPiR3lsAP+7y0t5w8CdI7aXAZQfmp73LYPhjtRfovczPe8Phj/ReCv243U98w+GPFF8KNF/mZ77h8EeaLwWqL/NT33D4I9WXAt2X+blvOPyR7kuB8sv85Dcc/kj5pUD7ZX72Gw5/pP1SoP4yP/0Nhz9SfynQfxM//w2Gf4r0Xwb038TPf9Ng+CPxA/U38dPfYPAjVx8Y9NvOfvYbDH7k5JMB5Tfxk99g8CPXHhjQfRM/9w0GP3LqyYDqm/ipbzD4kSsPDGi+iZ/5hvPWi515As038TPfYPgjFx4YUHwTP/ENZ+JPHwEHmm7qZ7rBAEcuNCRA0U0votuPle3e1KU5uz0TZz7rI/QqhfnfX37Yn93L+2KIG1HLjTBwPWR3xsxroP9uwGB+5upSajtupvzX5LdPDKnvpyjdwfZgVEP5bHRbSmVjkPUzb3qBrfDo374z/PBLlvm9S3exy1433Cw6rkTzYFpn3+JmY6XQWPHjWBmsFNwa6idKYbpj2gZKyO2u0qNxP7NPl1FaPM0lswQlE1+n8j5yFqWrKItng69Awd939GPeGZ0NfZm+dEZvDW9bXjVi0XeC/xSPKtNepDu1eR55b7X5idJ8rY+rm/iHkjteRrjbbN8+hJmu6ilAuefNKErZl50c6t1rUblHKPSDGVtL4uxFSg/iNEnHldxMidn273PpGn6oeP2z3OtmdN2Lv9qx8rZ12+iKN43laXOyydn/9V9lp5tDt9PqcL4TuB3C3PRzZ4+ddpybT1u0KlvenTe5J028Qp+yhD1n4nS6VvQ937rdfxgu1Zcf/ZfvO262Um1/IbNFWSCLkqUzlZDFUcbmhmsWo8psJrgrYFsLUZbMxqe4Sps5wWrKPp2NzpBw4uVN+OJe5gmKzG3kiblNPMqy2fgpjszMCe5Cv9zIK7ldiMYWn7GTSlsE4m4PaHFzk3PRn6LTsF5fPW0lIntbL1MEltN0VbBVnufLgrLj8R+lbsBH' --[[red research]] Public[4] = '0eNqdnNtu4zgMht/F187ApKxTXmVRLJLU2xpInMBxFlsM8u5rN2nSTs2UPy8Gg85Qn0mKlEhJ6O9ivT01h77thmL5uzh2q8Ni2C9e+vZ5+vm/Yum4LN6mv85lsVof99vT0CwmuUPbvRTLoT81ZdFu9t2xWP41EtqXbrWdxg5vh6ZYFu3Q7Iqy6Fa76aehX3XHw74fFutmOxQjs+2em/EzdH4qi6Yb2qFtLqT3H97+7k67ddOPAhKjLA774zhs3101Tr/8u8r8y4/857ZvNpf/HU34hmU1NiJYp8ZShXBrNTcjWK9XlxFu0HMJ4UY9t0a4Sc91CDfruQHhUqUHewisTzeC8o30CUdQxpE+5VhMuXoOrM85gpKO7lnXdsemH8Z/FBezWkUM8Go2hvF5jhRhUi2Q7jm1Oh6b3Xo77huL3Wrz2nbNgh4siBIwK9x2W6ZUfuMKz3tBOyY8DGtNGDLjYKcC3xPnuFttt4tmO4r37WZx2G8bOSLDO7xr2pfX9f7UT5s2x9LXT3PfqOFw8oJ/PUwKAilYAzMKwIg58hajc550pfeznjRsUZIrM44SfOkqPDiDJjidIZ28CszA4htVJZ+DI1MIJIdnSxJIHlkrdWYGPGokOyOOkgy9p8V2tX5QS2RhfMbjLGnirDZkRlSB6bHF7B5bXCMJMC19iuYEzwBJOTwD3lWcQ3nrMi8SA5JUStcZUkHUz7BFSPOgqrUyZKo3ZMR38lxKeMNmkVVgxnZ2pi/0Lzu7z3PbuncKR9+w390R5pi1rbAjBuoR741Fz9xXRo2nEjKXabaK9Iat5/0zcyxLwpHA0m4+ojIZdGJ+5EQWpipUUDKT6oDHkHLfyXM5FxjKCNJkRHDKPVOaqKDflz7OcUhoFIOmNIufIT+bh3Y0+ScdI34uSKqOOyRNLBJmfsZPBXXkaDgfkHwaycASTmki4+EoNIPR4SihGYyG4i2opsHDdwBKcICP1ZXgiN8DKMkJP1pXkrMh6VXkVBkSVAiyRAaWEPuJDRYLPW1yBpbQ1CawgLuvF2mmLPAlEY1/ZuvP5A3ulFwQDCzJBZ/O1Ib9uIv9c+q71WbO+Opy8k6zmGSYFaEnSob8YKFVy5aMEPTKhowQ9WK12+MDt2cHnDEwa9aQXCNIVVWY8SNlFurDjF/AsNBUZDjy3SwGKrSUc5AhpmoSqKoMaSX4jioywFiCsSGxRM2cASZqpkmG+8Wv8krZQ1DSQQO6oLh5i6NGuQRanCCo0uJsuDaWJhq5588/heCnu33oXIjd96piLFGEioKAm/7bF3S33ISfM7N0mUx4s8LSnTl5/HWO0uJgeE+kREfDGx0l2lB1adHZWBrPBfGUEVMg8+ypI1leByjNYEvNpkSz4WmQEu0Mz5mUaLTlSQ/ndX5lAt4QUAT1D4Z3U0p0NOwB0rKHPCPIP617wEOCm81CW0/AS4Iby0sswtd2US/DQ1FRL8P+lSRWjftLZOHnaxwllqETElkR1stVEivhNmaJlfHndpJewDuB+EWvp7IY2u31zfSfFlzew5z/qL0Pq+G1mJSYFQ+YeMTEEyaeMXGqMHlG5UkrnzHXZ8z1GXN9xlyfMddn0PVX+RqTZ5CPThUzKO9AebW91/McB8qjfL1D70er4ABGB6A2A04l0KkEOpWwDL7KR1Ben2UfAwgcwOgXgLBg0EcM+ohRHzHqI0bjlNE4dagNDrXhOoDRAQ4dABvt0QEZHMCoWxk1GpjpGp2HGp2HGp2HGp2HGp2HGp0HD64BHqt1ppM1iB9M/AzKA+kc0DAKaGQHNLIj6KMI+iiiPoqojyKaahFNtYjOQkRnAWy4COy4rvKAjxLqI7Tp+hjA6AC9DRk1Gu12CG1fCO1fCG1guMIi6SqfQXlCFdI7lQm0gEAL0Or8Y4BDB+hNZtAEtHhmtI5ktI5ktELixxXSU3n5bQTLT7/0oCz+bfrj5dQ9UR0zR+cSpZTO5/8BKB79Hw==' diff --git a/maps/chronosphere/worlds/caveworld.lua b/maps/chronosphere/worlds/caveworld.lua index 835a81b3..6f7720dd 100644 --- a/maps/chronosphere/worlds/caveworld.lua +++ b/maps/chronosphere/worlds/caveworld.lua @@ -66,7 +66,7 @@ local function process_tile(p, seed, tiles, entities, treasure, decoratives) if noise3 > -0.25 and noise3 < 0.25 then tiles[#tiles + 1] = {name = 'dirt-6', position = p} - local evo = game.forces['enemy'].evolution_factor + local evo = game.forces.enemy.get_evolution_factor(game.get_surface(objective.active_surface_index)) local roll = random(1, 1000) if roll > 830 + tunnels then entities[#entities + 1] = {name = Raffle.rocks[random(1, #Raffle.rocks)], position = p} diff --git a/maps/chronosphere/worlds/locomotive_surface.lua b/maps/chronosphere/worlds/locomotive_surface.lua index c100b3e7..6b9f1e04 100644 --- a/maps/chronosphere/worlds/locomotive_surface.lua +++ b/maps/chronosphere/worlds/locomotive_surface.lua @@ -3,6 +3,7 @@ local Chrono_table = require 'maps.chronosphere.table' local Factories = require 'maps.chronosphere.production' local Upgrades = require 'maps.chronosphere.upgrade_list' local List = require 'maps.chronosphere.production_list' +local Functions = require 'maps.chronosphere.world_functions' local math_floor = math.floor local math_random = math.random @@ -14,6 +15,13 @@ local function protect(entity, operable) entity.operable = operable end +local function connect_entities(entity1, entity2, wire_type) + local wireconnector1 = entity1.get_wire_connector(wire_type, true) + local wireconnector2 = entity2.get_wire_connector(wire_type, true) + wireconnector1.connect_to(wireconnector2) +end + + function Public.create_wagon_room() local objective = Chrono_table.get_table() local width = 64 @@ -132,61 +140,79 @@ function Public.create_wagon_room() end surface.set_tiles(water_tiles) - local combinators = {} - for x = width * -0.5 - 6, width * -0.5 + 3, 1 do - for y = -250, -244, 2 do - combinators[#combinators + 1] = {name = 'arithmetic-combinator', position = {x, y}, force = 'player', create_build_effect_smoke = false} - end - end - local combimade = {} - for i = 1, #combinators, 1 do - combimade[i] = surface.create_entity(combinators[i]) - protect(combimade[i], false) + Functions.build_blueprint(surface, {-38, -251}, 1, "player") + -- local combinators = {} + -- for x = width * -0.5 - 6, width * -0.5 + 3, 1 do + -- for y = -250, -244, 2 do + -- combinators[#combinators + 1] = {name = 'arithmetic-combinator', position = {x, y}, force = 'player', create_build_effect_smoke = false} + -- end + -- end + -- local combimade = {} + -- for i = 1, #combinators, 1 do + -- combimade[i] = surface.create_entity(combinators[i]) + -- protect(combimade[i], false) - if i > 1 then - combimade[i].connect_neighbour({wire = defines.wire_type.green, target_entity = combimade[i - 1], source_circuit_id = 2, target_circuit_id = 1}) - local rule = combimade[i].get_or_create_control_behavior() - rule.parameters = {first_signal = {type = 'virtual', name = 'signal-A'}, second_constant = 0, operation = '+', output_signal = {type = 'virtual', name = 'signal-A'}} - else - local rule2 = combimade[i].get_or_create_control_behavior() - rule2.parameters = {first_signal = {type = 'virtual', name = 'signal-A'}, second_constant = 0, operation = '+', output_signal = {type = 'virtual', name = 'signal-B'}} - end - end - local checker = surface.create_entity({name = 'decider-combinator', position = {x = width * -0.5 - 6, y = -242}, force = 'player', create_build_effect_smoke = false}) - local rules3 = checker.get_or_create_control_behavior() - rules3.parameters = { - first_signal = {type = 'virtual', name = 'signal-A'}, - second_signal = {type = 'virtual', name = 'signal-B'}, - comparator = '>', - output_signal = {type = 'virtual', name = 'signal-C'}, - copy_count_from_input = false - } - local combipower = surface.create_entity({name = 'substation', position = {x = width * -0.5 - 4, y = -242}, force = 'player', create_build_effect_smoke = false}) - combipower.connect_neighbour({wire = defines.wire_type.green, target_entity = checker, target_circuit_id = 1}) - combipower.connect_neighbour({wire = defines.wire_type.green, target_entity = combimade[#combimade], target_circuit_id = 1}) - combimade[1].connect_neighbour({wire = defines.wire_type.green, target_entity = checker, source_circuit_id = 2, target_circuit_id = 1}) - local speaker = - surface.create_entity( - { - name = 'programmable-speaker', - position = {x = width * -0.5 - 6, y = -241}, - force = 'player', - create_build_effect_smoke = false, - parameters = {playback_volume = 0.6, playback_globally = true, allow_polyphony = false}, - alert_parameters = {show_alert = true, show_on_map = true, icon_signal_id = {type = 'item', name = 'accumulator'}, alert_message = 'Train Is Charging!'} - } - ) - speaker.connect_neighbour({wire = defines.wire_type.green, target_entity = checker, target_circuit_id = 2}) - local rules4 = speaker.get_or_create_control_behavior() - rules4.circuit_condition = {condition = {first_signal = {type = 'virtual', name = 'signal-C'}, second_constant = 0, comparator = '>'}} - rules4.circuit_parameters = {signal_value_is_pitch = false, instrument_id = 8, note_id = 5} - local solar1 = surface.create_entity({name = 'solar-panel', position = {x = width * -0.5 - 2, y = -242}, force = 'player', create_build_effect_smoke = false}) - local solar2 = surface.create_entity({name = 'solar-panel', position = {x = width * -0.5 + 1, y = -242}, force = 'player', create_build_effect_smoke = false}) - protect(solar1, true) - protect(solar2, true) - protect(combipower, false) - protect(speaker, false) - protect(checker, false) + -- if i > 1 then + -- combimade[i].connect_neighbour({wire = defines.wire_type.green, target_entity = combimade[i - 1], source_circuit_id = 2, target_circuit_id = 1}) + -- local rule = combimade[i].get_or_create_control_behavior() + -- rule.parameters = {first_signal = {type = 'virtual', name = 'signal-A'}, second_constant = 0, operation = '+', output_signal = {type = 'virtual', name = 'signal-A'}} + -- else + -- local rule2 = combimade[i].get_or_create_control_behavior() + -- rule2.parameters = {first_signal = {type = 'virtual', name = 'signal-A'}, second_constant = 0, operation = '+', output_signal = {type = 'virtual', name = 'signal-B'}} + -- end + -- end + -- local checker = surface.create_entity({name = 'decider-combinator', position = {x = width * -0.5 - 6, y = -242}, force = 'player', create_build_effect_smoke = false}) + -- if not checker or not checker.valid then return end + -- local rules3 = checker.get_control_behavior() + -- local dec_condition = { + -- first_signal = {type = 'virtual', name = 'signal-A'}, + -- second_signal = {type = 'virtual', name = 'signal-B'}, + -- comparator = '>', + + -- } + -- local dec_output = { + -- output_signal = {type = 'virtual', name = 'signal-C'}, + -- copy_count_from_input = false + -- } + + -- rules3.set_condition(1, dec_condition) + -- rules3.set_output(1, dec_output) + -- rules3.parameters = { + -- first_signal = {type = 'virtual', name = 'signal-A'}, + -- second_signal = {type = 'virtual', name = 'signal-B'}, + -- comparator = '>', + -- output_signal = {type = 'virtual', name = 'signal-C'}, + -- copy_count_from_input = false + -- } + -- local combipower = surface.create_entity({name = 'substation', position = {x = width * -0.5 - 4, y = -242}, force = 'player', create_build_effect_smoke = false}) + -- connect_entities(combipower, checker, defines.wire_connector_id.circuit_green) + + -- combipower.connect_neighbour({wire = defines.wire_type.green, target_entity = checker, target_circuit_id = 1}) + -- combipower.get_wire_connector(defines.wire_connector_id.circuit_green, true).connect_to(checker.get_wire_connector(defines.wire_connector_id.circuit_green, true), false) + -- combipower.connect_neighbour({wire = defines.wire_type.green, target_entity = combimade[#combimade], target_circuit_id = 1}) + -- combimade[1].connect_neighbour({wire = defines.wire_type.green, target_entity = checker, source_circuit_id = 2, target_circuit_id = 1}) + -- local speaker = + -- surface.create_entity( + -- { + -- name = 'programmable-speaker', + -- position = {x = width * -0.5 - 6, y = -241}, + -- force = 'player', + -- create_build_effect_smoke = false, + -- parameters = {playback_volume = 0.6, playback_globally = true, allow_polyphony = false}, + -- alert_parameters = {show_alert = true, show_on_map = true, icon_signal_id = {type = 'item', name = 'accumulator'}, alert_message = 'Train Is Charging!'} + -- } + -- ) + -- speaker.connect_neighbour({wire = defines.wire_type.green, target_entity = checker, target_circuit_id = 2}) + -- local rules4 = speaker.get_or_create_control_behavior() + -- rules4.circuit_condition = {condition = {first_signal = {type = 'virtual', name = 'signal-C'}, second_constant = 0, comparator = '>'}} + -- rules4.circuit_parameters = {signal_value_is_pitch = false, instrument_id = 8, note_id = 5} + -- local solar1 = surface.create_entity({name = 'solar-panel', position = {x = width * -0.5 - 2, y = -242}, force = 'player', create_build_effect_smoke = false}) + -- local solar2 = surface.create_entity({name = 'solar-panel', position = {x = width * -0.5 + 1, y = -242}, force = 'player', create_build_effect_smoke = false}) + -- protect(solar1, true) + -- protect(solar2, true) + -- protect(combipower, false) + -- protect(speaker, false) + -- protect(checker, false) for k, x in pairs({-1, 0}) do for i = 1, 12, 1 do @@ -196,24 +222,24 @@ function Public.create_wagon_room() protect(e, true) --e.link_id = 1000 + i + 12 * (k - 1) table.insert(objective.comfychests2, e) - table.insert(objective.comfychest_invs2, e.get_inventory(defines.inventory.chest)) + table.insert(objective.comfychest_invs2, e and e.get_inventory(defines.inventory.chest)) end end for i = 1, 9, 1 do local y = -0.7 * height + 18 + 9 + 18 * (math_floor((i - 1) / 3)) local x = -0.5 * width + 5 + 9 + 18 * (i % 3) - local substation = surface.create_entity({name = 'substation', position = {x, y}, force = 'player', create_build_effect_smoke = false}) - if i == 3 then - substation.disconnect_neighbour(combipower) - substation.connect_neighbour({wire = defines.wire_type.green, target_entity = combipower}) - end - protect(substation, true) + -- local substation = surface.create_entity({name = 'substation', position = {x, y}, force = 'player', create_build_effect_smoke = false}) + -- if i == 3 then + -- substation.disconnect_neighbour(combipower) + -- substation.connect_neighbour({wire = defines.wire_type.green, target_entity = combipower}) + -- end + -- protect(substation, true) for j = 1, 4, 1 do local xx = x - 2 * j local acumulator = surface.create_entity({name = 'accumulator', position = {xx, y}, force = 'player', create_build_effect_smoke = false}) if i == 3 and j == 1 then - acumulator.connect_neighbour({wire = defines.wire_type.green, target_entity = substation}) + --acumulator.connect_neighbour({wire = defines.wire_type.green, target_entity = substation}) end protect(acumulator, true) table.insert(objective.accumulators, acumulator) @@ -234,8 +260,11 @@ function Public.create_wagon_room() rendering.draw_text { text = {'chronosphere.train_laser_battery'}, surface = surface, - target = laser_battery, - target_offset = {0, -2.5}, + target = { + entity = laser_battery, + offset = {0, -2.5}, + position = laser_battery and laser_battery.position + }, color = objective.locomotive.color, scale = 1.00, font = 'default-game', @@ -251,7 +280,11 @@ function Public.create_wagon_room() rendering.draw_text { text = {'chronosphere.train_repair_chest'}, surface = surface, - target = repairchest, + target = { + entity = repairchest, + offset = {0, -2.5}, + position = repairchest and repairchest.position + }, target_offset = {0, -2.5}, color = objective.locomotive.color, scale = 1.00, @@ -267,8 +300,11 @@ function Public.create_wagon_room() rendering.draw_sprite { sprite = upgrades[i].sprite, surface = surface, - target = e, - target_offset = {0, -1.3}, + target = { + entity = e, + offset = {0, -1.3}, + position = e and e.position + }, font = 'default-game', visible = true } @@ -277,7 +313,11 @@ function Public.create_wagon_room() rendering.draw_text { text = {'chronosphere.train_market'}, surface = surface, - target = market, + target = { + entity = market, + offset = {0, -3.5}, + position = market and market.position + }, target_offset = {0, -3.5}, color = objective.locomotive.color, scale = 1.00, @@ -288,8 +328,11 @@ function Public.create_wagon_room() rendering.draw_text { text = {'chronosphere.train_upgrades'}, surface = surface, - target = objective.upgradechest[8], - target_offset = {0, -3.5}, + target = { + entity = objective.upgradechest[8], + offset = {0, -3.5}, + position = objective.upgradechest[8].position + }, color = objective.locomotive.color, scale = 1.00, font = 'default-game', @@ -299,8 +342,11 @@ function Public.create_wagon_room() rendering.draw_text { text = {'chronosphere.train_upgrades_sub'}, surface = surface, - target = objective.upgradechest[8], - target_offset = {0, -2.5}, + target = { + entity = objective.upgradechest[8], + offset = {0, -2.5}, + position = objective.upgradechest[8].position + }, color = objective.locomotive.color, scale = 0.80, font = 'default-game', @@ -309,6 +355,7 @@ function Public.create_wagon_room() } for _, offer in pairs(Balance.market_offers()) do + if not market or not market.valid then break end market.add_market_item(offer) end @@ -324,6 +371,7 @@ function Public.create_wagon_room() objective.car_exits = {} for i = 1, 6, 1 do local e = surface.create_entity({name = 'car', position = car_pos[i], force = 'player', create_build_effect_smoke = false}) + if not e or not e.valid then break end e.get_inventory(defines.inventory.fuel).insert({name = 'wood', count = 16}) protect(e, false) objective.car_exits[i] = e @@ -352,7 +400,9 @@ function Public.create_wagon_room() break end local e = surface.create_entity({name = 'wooden-chest', position = positions[i], force = 'player', create_build_effect_smoke = false}) + if not e or not e.valid then break end local inventory = e.get_inventory(defines.inventory.chest) + if not inventory or not inventory.valid then break end inventory.insert({name = 'raw-fish', count = math_random(2, 5)}) i = i + 1 end @@ -371,7 +421,9 @@ function Public.create_wagon_room() break end local e = surface.create_entity({name = 'wooden-chest', position = positions[i], force = 'player', create_build_effect_smoke = false}) + if not e or not e.valid then break end local inventory = e.get_inventory(defines.inventory.chest) + if not inventory or not inventory.valid then break end inventory.insert(cargo_boxes[loot_i]) i = i + 1 end @@ -389,6 +441,7 @@ function Public.create_wagon_room() e.rotatable = false Factories.register_train_assembler(e, key) if List[key].kind == 'assembler' or List[key].kind == 'fluid-assembler' then + if not e or not e.valid then break end e.set_recipe(List[key].recipe_override or List[key].name) e.recipe_locked = true e.direction = defines.direction.south diff --git a/maps/chronosphere/worlds/maze.lua b/maps/chronosphere/worlds/maze.lua index 94736883..2fb4ad1a 100644 --- a/maps/chronosphere/worlds/maze.lua +++ b/maps/chronosphere/worlds/maze.lua @@ -42,7 +42,7 @@ local function path_tile(p, tiles, entities, treasure, things) end else if random(1, 150) == 1 and Functions.distance(p.x, p.y) > 200 then - local evo = game.forces['enemy'].evolution_factor + local evo = game.forces['enemy'].get_evolution_factor(game.get_surface(objective.active_surface_index)) entities[#entities + 1] = {name = Raffle.worms[random(1 + floor(evo * 8), floor(1 + evo * 16))], position = p, spawn_decorations = true} end end diff --git a/maps/chronosphere/worlds/swamp.lua b/maps/chronosphere/worlds/swamp.lua index 3afd39cd..a04fc1fb 100644 --- a/maps/chronosphere/worlds/swamp.lua +++ b/maps/chronosphere/worlds/swamp.lua @@ -9,7 +9,7 @@ local Chrono_table = require 'maps.chronosphere.table' local function process_tile(p, seed, tiles, entities, treasure) local objective = Chrono_table.get_table() local noise1 = Functions.get_noise('scrapyard', p, seed) - local evo = game.forces['enemy'].evolution_factor + local evo = game.forces.enemy.get_evolution_factor(game.get_surface(objective.active_surface_index)) local handicap = max(0, 120 - objective.chronojumps * 20) if noise1 < -0.70 or noise1 > 0.70 then diff --git a/maps/expanse/main.lua b/maps/expanse/main.lua index 5e6cd631..212527f9 100644 --- a/maps/expanse/main.lua +++ b/maps/expanse/main.lua @@ -14,7 +14,6 @@ local Global = require 'utils.global' local Map_info = require 'modules.map_info' local Gui = require 'utils.gui' local format_number = require 'util'.format_number -local Random = require 'maps.chronosphere.random' local Autostash = require 'modules.autostash' local expanse = { @@ -125,7 +124,7 @@ local function reset() Functions.expand(expanse, { x = 0, y = 0 }) for _, player in pairs(game.players) do - player.teleport(surface.find_non_colliding_position('character', { expanse.square_size * 0.5, expanse.square_size * 0.5 }, 8, 0.5), surface) + player.teleport(surface.find_non_colliding_position('character', { expanse.square_size * 0.5, expanse.square_size * 0.5 }, 8, 0.5) or {5, 5}, surface) end end @@ -241,7 +240,7 @@ local function container_opened(event) game.print({ 'expanse.tile_unlock', colored_player_name, { 'expanse.gps', math.floor(expansion_position.x), math.floor(expansion_position.y), 'expanse' } }) expanse.size = (expanse.size or 1) + 1 if math.random(1, 4) == 1 then - if surface.count_tiles_filtered({ position = expansion_position, radius = 6, collision_mask = 'water_tile' }) > 40 then + if surface and surface.count_tiles_filtered({ position = expansion_position, radius = 6, collision_mask = 'water_tile' }) > 40 then return end local render = rendering.draw_sprite { @@ -424,7 +423,7 @@ local function create_main_frame(player) frame.add({ type = 'label', name = 'biters', caption = { 'expanse.stats_attack', #expanse.invasion_candidates, invasion_numbers.candidates, invasion_numbers.groups } }) local scroll = frame.add({ type = 'scroll-pane', name = 'scroll_pane', horizontal_scroll_policy = 'never', vertical_scroll_policy = 'auto-and-reserve-space' }) local frame_table = scroll.add({ type = 'table', name = 'resource_stats', column_count = 8 }) - for name, count in Random.spairs(expanse.cost_stats, function (t, a, b) return t[a] > t[b] end) do + for name, count in table.spairs(expanse.cost_stats, function (t, a, b) return t[a] > t[b] end) do resource_stats(frame_table, name, count) end end diff --git a/modules/admins_operate_biters.lua b/modules/admins_operate_biters.lua index bbf07445..a3b0ca75 100644 --- a/modules/admins_operate_biters.lua +++ b/modules/admins_operate_biters.lua @@ -1,5 +1,6 @@ --luacheck: ignore -local event = require 'utils.event' +local Event = require 'utils.event' +local AI = require 'utils.functions.AI' local math_random = math.random local math_floor = math.floor storage.biter_command = {} @@ -31,29 +32,9 @@ local worm_raffle = { 'behemoth-worm-turret' } -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 function is_closer(pos1, pos2, pos) - return ((pos1.x - pos.x) ^ 2 + (pos1.y - pos.y) ^ 2) < ((pos2.x - pos.x) ^ 2 + (pos2.y - pos.y) ^ 2) -end -local function shuffle_distance(tbl, position) - local size = #tbl - for i = size, 1, -1 do - local rand = math_random(size) - if is_closer(tbl[i].position, tbl[rand].position, position) and i > rand then - tbl[i], tbl[rand] = tbl[rand], tbl[i] - end - end - return tbl -end + local function get_evo(force) local evo = math_floor(game.forces['enemy'].evolution_factor * 20) @@ -71,7 +52,7 @@ local function place_nest_near_unit_group(group) return false end local units = group.members - shuffle(units) + table.shuffle_table(units) for i = 1, 5, 1 do if not units[i].valid then return false @@ -105,7 +86,7 @@ local function build_worm(group) return false end local units = group.members - shuffle(units) + table.shuffle_table(units) for i = 1, 5, 1 do if not units[i].valid then return false @@ -142,15 +123,6 @@ end -----------commands----------- -local function move_to(position, distraction) - local command = { - type = defines.command.go_to_location, - destination = position, - distraction = distraction, - pathfind_flags = { allow_destroy_friendly_entities = true } - } - return command -end -- local function attackmaincommand(target) -- local wave_defense_table = WD.get_table() @@ -164,34 +136,7 @@ end -- return command -- end -local function attackareacommand(position) - local command = { - type = defines.command.attack_area, - destination = position, - radius = 25, - distraction = defines.distraction.by_enemy - } - return command -end -local function attackobstaclescommand(surface, position) - local commands = {} - local obstacles = surface.find_entities_filtered { position = position, radius = 20, type = { 'simple-entity', 'tree' }, limit = 100 } - if obstacles then - shuffle(obstacles) - shuffle_distance(obstacles, position) - for i = 1, #obstacles, 1 do - if obstacles[i].valid then - commands[#commands + 1] = { - type = defines.command.attack, - target = obstacles[i], - distraction = defines.distraction.by_enemy - } - end - end - end - return commands -end local function get_coords(group, source_player) local position @@ -231,14 +176,14 @@ local function disband(group, source_player) end local function movetome(group, source_player) - group.set_command(move_to(source_player.position, defines.distraction.none)) + group.set_command(AI.command_move_to(source_player.position, defines.distraction.none)) flying_text(nil, 1, group.position, source_player) end local function movetoposition(group, source_player) local position = get_coords(group, source_player) if position then - group.set_command(move_to(position, defines.distraction.none)) + group.set_command(AI.command_move_to(position, defines.distraction.none)) flying_text(nil, 1, group.position, source_player) else flying_text(nil, 2, group.position, source_player) @@ -246,14 +191,14 @@ local function movetoposition(group, source_player) end local function patroltome(group, source_player) - group.set_command(move_to(source_player.position, defines.distraction.by_enemy)) + group.set_command(AI.command_move_to(source_player.position, defines.distraction.by_enemy)) flying_text(nil, 1, group.position, source_player) end local function patroltoposition(group, source_player) local position = get_coords(group, source_player) if position then - group.set_command(move_to(position, defines.distraction.by_enemy)) + group.set_command(AI.command_move_to(position, defines.distraction.by_enemy)) flying_text(nil, 1, group.position, source_player) else flying_text(nil, 2, group.position, source_player) @@ -288,11 +233,11 @@ end local function attackenemiesaround(group, source_player) flying_text(nil, 3, group.position, source_player) - group.set_command(attackareacommand(group.position)) + group.set_command(AI.command_attack_area(group.position, 25)) end local function attackobstaclesaround(group, source_player) - local commands = attackobstaclescommand(group.surface, group.position) + local commands = AI.command_attack_obstacles(group.surface, group.position) if #commands > 1 then group.set_command( { @@ -309,12 +254,12 @@ local function attackobstaclesaround(group, source_player) end local function attackenemiesaroundme(group, source_player) - group.set_command(attackareacommand(source_player.position)) + group.set_command(AI.command_attack_area(source_player.position, 25)) flying_text(nil, 3, group.position, source_player) end local function attackobstaclesaroundme(group, source_player) - local commands = attackobstaclescommand(source_player.surface, source_player.position) + local commands = AI.command_attack_obstacles(source_player.surface, source_player.position) if #commands > 1 then group.set_command( { @@ -708,7 +653,7 @@ local function on_unit_removed_from_group(event) end end -event.add(defines.events.on_unit_removed_from_group, on_unit_removed_from_group) -event.add(defines.events.on_unit_group_created, on_unit_group_created) -event.add(defines.events.on_player_joined_game, on_player_joined_game) -event.add(defines.events.on_gui_click, on_gui_click) +Event.add(defines.events.on_unit_removed_from_group, on_unit_removed_from_group) +Event.add(defines.events.on_unit_group_created, on_unit_group_created) +Event.add(defines.events.on_player_joined_game, on_player_joined_game) +Event.add(defines.events.on_gui_click, on_gui_click) diff --git a/modules/biters_yield_coins.lua b/modules/biters_yield_coins.lua index 78708286..6809a4bd 100644 --- a/modules/biters_yield_coins.lua +++ b/modules/biters_yield_coins.lua @@ -103,13 +103,13 @@ local function on_entity_died(event) end end if entities_that_earn_coins[event.cause.name] then - event.entity.surface.spill_item_stack(event.cause.position, { name = 'coin', count = coin_count }, true) + event.entity.surface.spill_item_stack({position = event.cause.position, stack = { name = 'coin', count = coin_count }, enable_looted = true}) reward_has_been_given = true end end if reward_has_been_given == false then - event.entity.surface.spill_item_stack(event.entity.position, { name = 'coin', count = coin_count }, true) + event.entity.surface.spill_item_stack({position = event.entity.position, stack = { name = 'coin', count = coin_count }, enable_looted = true}) end end diff --git a/modules/biters_yield_ore.lua b/modules/biters_yield_ore.lua index 10b23988..6e88a2e1 100644 --- a/modules/biters_yield_ore.lua +++ b/modules/biters_yield_ore.lua @@ -56,7 +56,7 @@ local function on_tick() local surface = game.surfaces[entry[3]] for _ = 1, 3, 1 do local vector = drop_vectors[math_random(1, size_of_drop_vectors)] - surface.spill_item_stack({ entry[1][1] + vector[1], entry[1][2] + vector[2] }, { name = drop_raffle[math_random(1, size_of_drop_raffle)], count = 1 }, true) + surface.spill_item_stack({position = { entry[1][1] + vector[1], entry[1][2] + vector[2] }, stack = { name = drop_raffle[math_random(1, size_of_drop_raffle)], count = 1 }, enable_looted = true}) storage.biters_drop_ore[key][2] = storage.biters_drop_ore[key][2] - 1 if storage.biters_drop_ore[key][2] <= 0 then table_remove(storage.biters_drop_ore, key) diff --git a/utils/functions/AI.lua b/utils/functions/AI.lua new file mode 100644 index 00000000..8c876c5d --- /dev/null +++ b/utils/functions/AI.lua @@ -0,0 +1,108 @@ +--library to make working with unit commands easier + +local Public = {} + +local Global = require 'utils.global' +local Utils = require 'utils.utils' + +---Command to move +---@param position MapPosition +---@param distraction defines.distraction|nil +function Public.command_move_to(position, distraction) + local command = { + type = defines.command.go_to_location, + destination = position, + distraction = distraction or defines.distraction.by_enemy, + no_break = true + } + return command +end + +---Command to attack entity +---@param target LuaEntity +---@param distraction defines.distraction|nil +function Public.command_attack_target(target, distraction) + local command = { + type = defines.command.attack, + target = target, + distraction = distraction or defines.distraction.by_enemy + } + return command +end + +---Command to attack things in area +---@param position MapPosition +---@param radius integer +---@param distraction defines.distraction|nil +function Public.command_attack_area(position, radius, distraction) + local command = { + type = defines.command.attack_area, + destination = position, + radius = radius or 25, + distraction = distraction or defines.distraction.by_enemy + } + return command +end + +---Command to attack natural obstacles +---@param surface LuaSurface +---@param position MapPosition +---@param distraction defines.distraction|nil +function Public.command_attack_obstacles(surface, position, distraction) + local commands = {} + local obstacles = surface.find_entities_filtered {position = position, radius = 25, type = {'simple-entity', 'tree', 'simple-entity-with-owner'}, limit = 100} + if obstacles then + --table.shuffle_table(obstacles) + table.shuffle_by_distance(obstacles, position) + for i = 1, #obstacles, 1 do + if obstacles[i].valid then + commands[#commands + 1] = { + type = defines.command.attack, + target = obstacles[i], + distraction = distraction + } + end + end + end + commands[#commands + 1] = Public.command_move_to(position) + local command = { + type = defines.command.compound, + structure_type = defines.compound_command.return_last, + commands = commands + } + return command +end + +---Give list of commands to unit or group +---@param unit LuaCommandable +---@param commands Command +function Public.multicommand(unit, commands) + if #commands > 0 then + local command = { + type = defines.command.compound, + structure_type = defines.compound_command.return_last, + commands = commands + } + unit.set_command(command) + end +end + +---Give list of commands to unit or group +---@param surface LuaSurface +---@param target LuaEntity +---@param force LuaForce +---@param size_multiplier number|nil #defaults to 1 if nil or less than 0 +function Public.multi_attack(surface, target, force, size_multiplier) + surface.set_multi_command( + { + command = Public.command_attack_target(target), + unit_count = 16 + math.random(1, math.floor(1 + force.get_evolution_factor(surface) * 100)) * ((size_multiplier or 1) > 0 and size_multiplier or 1), + force = force, + unit_search_distance = 512 + } + ) +end + +---TODO: more advanced functions and direct LuaCommandable stuff + +return Public \ No newline at end of file