diff --git a/maps/railway_troopers_v2/main.lua b/maps/railway_troopers_v2/main.lua new file mode 100644 index 00000000..c3ebf2c9 --- /dev/null +++ b/maps/railway_troopers_v2/main.lua @@ -0,0 +1,287 @@ +require "modules.dynamic_player_spawn" +require "modules.biters_yield_ore" +require "modules.difficulty_vote" + +local difficulties_votes = { + [1] = 16, + [2] = 8, + [3] = 6, + [4] = 4, + [5] = 3, + [6] = 2, + [7] = 1 +} + +local Immersive_cargo_wagons = require "modules.immersive_cargo_wagons.main" +local LootRaffle = require "functions.loot_raffle" + +local map_height = 64 + +local math_random = math.random +local math_floor = math.floor +local table_insert = table.insert +local table_remove = table.remove +local math_sqrt = math.sqrt +local math_round = math.round +local math_abs = math.abs + +local function place_spawn_entities(surface) + for x = 0, 96, 2 do + surface.create_entity({name = "straight-rail", position = {-96 + x, 0}, direction = 2, force = "player"}) + end + + local entity = surface.create_entity({name = "cargo-wagon", position = {-24, 1}, force = "player", direction = 2}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "firearm-magazine", count = 600}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "shotgun", count = 2}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "shotgun-shell", count = 64}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "light-armor", count = 5}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "grenade", count = 32}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "pistol", count = 10}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "rail", count = 100}) + Immersive_cargo_wagons.register_wagon(entity) + + local entity = surface.create_entity({name = "locomotive", position = {-18, 0}, force = "player", direction = 2}) + entity.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 25}) + Immersive_cargo_wagons.register_wagon(entity) +end + +local function treasure_chest(surface, position) + local budget = 32 + math_abs(position.x) * 2 + budget = budget * math_random(25, 175) * 0.01 + if math_random(1,200) == 1 then + budget = budget * 10 + container_name = "crash-site-chest-" .. math_random(1, 2) + end + budget = math_floor(budget) + 1 + + local item_stacks = LootRaffle.roll(budget, 16) + local container = surface.create_entity({name = "wooden-chest", position = position, force = "neutral"}) + for _, item_stack in pairs(item_stacks) do + container.insert(item_stack) + end + container.minable = false +end + +local infini_ores = {"iron-ore", "iron-ore", "copper-ore", "coal", "stone"} + +local function on_player_joined_game(event) + local surface = game.surfaces["railway_troopers"] + local player = game.players[event.player_index] + player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 32, 0.5), surface) +end + +local function on_entity_died(event) + local entity = event.entity + if not entity.valid then return end + + if entity.type == "unit" and entity.spawner then + entity.spawner.damage(20, game.forces[1]) + end +end + +local function is_out_of_map(p) + local b = math_abs(p.y) + if b > map_height then return true end +end + +local function map_reset() + game.reset_time_played() + Immersive_cargo_wagons.reset() + + global.drop_schedule = {} + global.on_entity_spawned_counter = 0 + global.collapse_x = -96 + global.collapse_tiles = {} + + reset_difficulty_poll() + global.difficulty_poll_closing_timeout = game.tick + 3600 + + game.map_settings.enemy_evolution.destroy_factor = 0.001 + game.map_settings.enemy_evolution.pollution_factor = 0 + game.map_settings.enemy_evolution.time_factor = 0 + game.map_settings.enemy_expansion.enabled = true + game.map_settings.enemy_expansion.max_expansion_cooldown = 900 + game.map_settings.enemy_expansion.min_expansion_cooldown = 900 + game.map_settings.enemy_expansion.settler_group_max_size = 128 + game.map_settings.enemy_expansion.settler_group_min_size = 32 + game.map_settings.enemy_expansion.max_expansion_distance = 16 + game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 0.25 + + local surface = game.surfaces.railway_troopers + local map_gen_settings = surface.map_gen_settings + map_gen_settings.seed = math_random(1, 999999999) + surface.map_gen_settings = map_gen_settings + surface.clear(true) + + surface.request_to_generate_chunks({0,0}, 8) + surface.force_generate_chunk_requests() + + for _, force in pairs(game.forces) do + force.reset() + force.reset_evolution() + end + local force = game.forces.player + force.set_spawn_position({-30, 0}, surface) + force.technologies["railway"].researched = true + force.technologies["engine"].researched = true + + local types_to_disable = { + ["ammo"] = true, + ["armor"] = true, + ["car"] = true, + ["gun"] = true, + ["capsule"] = true, + } + + for _, recipe in pairs(game.recipe_prototypes) do + if types_to_disable[recipe.subgroup.name] then + force.set_hand_crafting_disabled_for_recipe(recipe.name, true) + end + end +end + +local function draw_west_side(surface, left_top) + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local position = {x = left_top.x + x, y = left_top.y + y} + surface.set_tiles({{name = "out-of-map", position = position}}, true) + end + end +end + +local function draw_east_side(surface, left_top) + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local position = {x = left_top.x + x, y = left_top.y + y} + if is_out_of_map(position) then + surface.set_tiles({{name = "out-of-map", position = position}}, true) + else + if math_random(1, 256) == 1 and surface.can_place_entity({name = "wooden-chest", position = position}) then + treasure_chest(surface, position) + end + end + end + end +end + +local function on_player_died(event) + local player = game.players[event.player_index] + player.force.set_spawn_position({global.collapse_x + 32, 0}, game.surfaces.railway_troopers) +end + +local function on_chunk_generated(event) + local surface = event.surface + if surface.name ~= "railway_troopers" then return end + local left_top = event.area.left_top + + if left_top.x <= 0 then + for _, e in pairs(surface.find_entities_filtered({force = "enemy", area = event.area})) do + e.destroy() + end + end + + if left_top.x < -96 then + draw_west_side(surface, left_top) + else + draw_east_side(surface, left_top) + end +end + +local function on_research_finished(event) + event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 200 + event.research.force.character_item_pickup_distance_bonus = game.forces.player.mining_drill_productivity_bonus * 10 +end + +local negative_map_height = map_height * -1 + +local function on_tick() + local tick = game.ticks_played + local surface = game.surfaces.railway_troopers + + if tick % 3600 == 60 then + if global.reset_railway_troopers then + if global.reset_railway_troopers == 1 then + global.reset_railway_troopers = 2 + map_reset() + for _, player in pairs(game.players) do + if player.character and player.character.valid then + player.character.die() + else + player.clear_items_inside() + player.teleport({-30, 0}, surface) + end + end + return + end + if global.reset_railway_troopers == 2 then + place_spawn_entities(surface) + global.reset_railway_troopers = nil + return + end + return + end + if surface.count_entities_filtered({name = {"rail", "locomotive", "cargo-wagon"}, limit = 1}) == 0 then + game.print("All the rails have have been destroyed! Game Over!") + global.reset_railway_troopers = 1 + return + end + end + + local speed = difficulties_votes[global.difficulty_vote_index] + if tick % speed ~= 0 then return end + if not global.collapse_tiles then + global.collapse_tiles = surface.find_tiles_filtered({area = {{global.collapse_x - 1, negative_map_height}, {global.collapse_x, map_height + 1}}}) + global.size_of_collapse_tiles = #global.collapse_tiles + global.collapse_x = global.collapse_x + 1 + if global.size_of_collapse_tiles == 0 then global.collapse_tiles = nil return end + table.shuffle_table(global.collapse_tiles) + end + local tile = global.collapse_tiles[global.size_of_collapse_tiles] + if not tile then global.collapse_tiles = nil return end + global.size_of_collapse_tiles = global.size_of_collapse_tiles - 1 + for _, e in pairs(surface.find_entities_filtered({position = {tile.position.x + 1.5, tile.position.y + 0.5}})) do e.die() end + surface.set_tiles({{name = "out-of-map", position = tile.position}}, true) +end + +local function on_init() + local surface = game.surfaces[1] + local map_gen_settings = surface.map_gen_settings + map_gen_settings.height = 3 + map_gen_settings.width = 3 + surface.map_gen_settings = map_gen_settings + for chunk in surface.get_chunks() do + surface.delete_chunk({chunk.x, chunk.y}) + end + + local map_gen_settings = { + ["water"] = 0.50, + ["starting_area"] = 0.60, + terrain_segmentation = 20, + ["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}, + ["autoplace_controls"] = { + ["coal"] = {frequency = 2, size = 0.1, richness = 0.1}, + ["stone"] = {frequency = 2, size = 0.1, richness = 0.1}, + ["copper-ore"] = {frequency = 2, size = 0.1, richness = 0.1}, + ["iron-ore"] = {frequency = 2, size = 0.1, richness = 0.1}, + ["uranium-ore"] = {frequency = 2, size = 0.1, richness = 0.1}, + ["crude-oil"] = {frequency = 2, size = 1, richness = 0.1}, + ["trees"] = {frequency = 4, size = 0.25, richness = 1}, + ["enemy-base"] = {frequency = 256, size = 2, richness = 1}, + }, + } + game.create_surface("railway_troopers", map_gen_settings) + + global.reset_railway_troopers = 2 + + map_reset() +end + +local Event = require 'utils.event' +Event.on_init(on_init) +Event.add(defines.events.on_tick, on_tick) +Event.add(defines.events.on_player_died, on_player_died) +Event.add(defines.events.on_research_finished, on_research_finished) +Event.add(defines.events.on_entity_died, on_entity_died) +Event.add(defines.events.on_entity_spawned, on_entity_spawned) +Event.add(defines.events.on_player_joined_game, on_player_joined_game) +Event.add(defines.events.on_chunk_generated, on_chunk_generated) \ No newline at end of file diff --git a/modules/immersive_cargo_wagons/functions.lua b/modules/immersive_cargo_wagons/functions.lua index 0cbd63e4..4da287e0 100644 --- a/modules/immersive_cargo_wagons/functions.lua +++ b/modules/immersive_cargo_wagons/functions.lua @@ -574,8 +574,8 @@ function Public.toggle_minimap(icw, event) return end if event.button == defines.mouse_button_type.middle then - player_data.map_size = player_data.map_size + 60 - if player_data.map_size > 720 then player_data.map_size = 300 end + player_data.map_size = player_data.map_size + 50 + if player_data.map_size > 650 then player_data.map_size = 250 end element.style.minimal_height = player_data.map_size element.style.minimal_width = player_data.map_size element.style.maximal_height = player_data.map_size