diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index bc35d5c4..9e3876ef 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -634,6 +634,15 @@ local function on_entity_died(event) surface = entity.surface } + if entity.type == 'tree' then + if Locomotive.is_around_train(entity) then + entity.destroy() + return + end + angry_tree(entity, event.cause) + return + end + if entity_type[entity.type] then if Locomotive.is_around_train(entity) then entity.destroy() @@ -658,15 +667,6 @@ local function on_entity_died(event) end end - if entity.type == 'tree' then - if Locomotive.is_around_train(entity) then - entity.destroy() - return - end - angry_tree(event.entity, event.cause) - return - end - if entity.type == 'simple-entity' then Mining.entity_died_randomness(data) entity.destroy() @@ -707,8 +707,6 @@ function Public.loco_died() data.position = {x = 0, y = 0} end - this.survival_time = game.tick - this.last_reset - local msg = mapkeeper .. defeated_messages[random(1, #defeated_messages)] .. '\nBetter luck next time.' Alert.alert_all_players_location(data, msg, nil, 6000) Reset_map() @@ -849,9 +847,6 @@ local function on_robot_built_entity(event) local upg = this.upgrades local surface = entity.surface - local e = {x = entity.position.x, y = entity.position.y} - local get_tile = surface.get_tile(e) - local built = { ['land-mine'] = upg.landmine.built, ['flamethrower-turret'] = upg.flame_turret.built @@ -901,10 +896,6 @@ local function on_robot_built_entity(event) entity.destroy() end end - if get_tile.valid and get_tile.name == 'black-refined-concrete' then - entity.destroy() - return - end end local on_player_or_robot_built_tile = function(event) @@ -934,6 +925,9 @@ local on_player_or_robot_built_tile = function(event) if old_tile.name == 'hazard-concrete-right' then surface.set_tiles({{name = 'hazard-concrete-right', position = v.position}}, true) end + if old_tile.name == 'tutorial-grid' then + surface.set_tiles({{name = 'tutorial-grid', position = v.position}}, true) + end end end diff --git a/maps/mountain_fortress_v3/ic/functions.lua b/maps/mountain_fortress_v3/ic/functions.lua index 94cb22e3..361230fb 100644 --- a/maps/mountain_fortress_v3/ic/functions.lua +++ b/maps/mountain_fortress_v3/ic/functions.lua @@ -4,6 +4,7 @@ local Task = require 'utils.task' local Token = require 'utils.token' local Public = {} +local random = math.random local function validate_entity(entity) if not entity then @@ -27,6 +28,27 @@ local function upperCase(str) return (str:gsub('^%l', string.upper)) end +local function render_owner_text(player, entity) + local color = { + r = player.color.r * 0.6 + 0.25, + g = player.color.g * 0.6 + 0.25, + b = player.color.b * 0.6 + 0.25, + a = 1 + } + rendering.draw_text { + text = '## - ' .. player.name .. "'s " .. entity.name .. ' - ##', + surface = entity.surface, + target = entity, + target_offset = {0, -2.6}, + color = color, + scale = 1.05, + font = 'default-large-semibold', + alignment = 'center', + scale_with_zoom = false + } + entity.color = color +end + local function kill_doors(ic, car) if not validate_entity(car.entity) then return @@ -47,6 +69,42 @@ local function get_owner_car_object(cars, player) return false end +local function get_player_surface(ic, player) + local surfaces = ic.surfaces + for k, surface in pairs(surfaces) do + if validate_entity(surface) then + if surface.index == player.surface.index then + return true + end + end + end + return false +end + +local function get_player_entity(ic, player) + local cars = ic.cars + for k, car in pairs(cars) do + if car.owner == player.index and type(car.entity) == 'boolean' then + return car.name, true + elseif car.owner == player.index then + return car.name, false + end + end + return false, false +end + +local function is_owner_on_car_surface(ic, player) + local cars = ic.cars + for k, car in pairs(cars) do + if validate_entity(car.surface) then + if car.owner == player.index and car.surface.index == player.surface.index then + return true + end + end + end + return false +end + local function get_owner_car_name(ic, player) local cars = ic.cars local saved_surfaces = ic.saved_surfaces @@ -70,8 +128,7 @@ local function get_saved_entity(cars, entity, index) { 'The built entity is not the same as the saved one. ', 'Saved entity is: ' .. - upperCase(car.name) .. ' - Built entity is: ' .. upperCase(entity.name) .. '. ', - 'This is not a bug. Do not report this!' + upperCase(car.name) .. ' - Built entity is: ' .. upperCase(entity.name) .. '. ' } ) return false, msg @@ -145,6 +202,13 @@ local function remove_logistics(car) end end +local function remove_simply_entity(car) + local surface = car.surface + for _, entity in pairs(surface.find_entities_filtered {name = 'sand-rock-big'}) do + entity.destroy() + end +end + local function set_new_area(ic, car) local new_area = ic.car_areas local name = car.name @@ -167,6 +231,7 @@ local function upgrade_surface(ic, player, entity) local c = get_owner_car_object(cars, player) local car = ic.cars[c] car.name = 'tank' + remove_simply_entity(car) set_new_area(ic, car) remove_logistics(car) replace_entity(cars, ce, index) @@ -252,7 +317,6 @@ local function restore_surface(ic, player, entity) local success, msg = get_saved_entity(cars, ce, index) if not success then player.print(msg, Color.warning) - ce.destroy() return true end replace_entity(cars, ce, index) @@ -260,6 +324,7 @@ local function restore_surface(ic, player, entity) replace_surface(surfaces, ce, index) replace_surface_entity(cars, ce, index) saved_surfaces[player.index] = nil + render_owner_text(player, ce) return true end return false @@ -431,14 +496,7 @@ function Public.save_car(ic, event) if car.owner == player.index then save_surface(ic, entity, player) if not ic.players[player.index].notified then - player.print( - player.name .. - ', the ' .. - car.name .. - ' surface has been saved. Do notice that you can´t place down anything else other than a ' .. - car.name .. '.', - Color.success - ) + player.print(player.name .. ', the ' .. car.name .. ' surface has been saved.', Color.success) ic.players[player.index].notified = true end else @@ -493,6 +551,24 @@ function Public.kill_car(ic, entity) ic.cars[entity.unit_number] = nil end +function Public.validate_owner(ic, player, entity) + if validate_entity(entity) then + local cars = ic.cars + local unit_number = entity.unit_number + local car = cars[unit_number] + if car and car.entity and validate_entity(car.entity) then + local p = game.players[car.owner] + if p then + if car.owner ~= player.index and player.driving then + return Utils.print_to(nil, '{Car} ' .. player.name .. ' is driving ' .. p.name .. '´s car.') + end + end + end + return false + end + return false +end + function Public.create_room_surface(ic, unit_number) if game.surfaces[tostring(unit_number)] then return game.surfaces[tostring(unit_number)] @@ -544,6 +620,12 @@ function Public.create_car_room(ic, car) end end + if entity_name == 'car' then + surface.create_entity({name = 'sand-rock-big', position = {0, 20}}) + elseif entity_name == 'tank' then + surface.create_entity({name = 'sand-rock-big', position = {0, 40}}) + end + local fishes = {} for x = area.left_top.x, area.right_bottom.x - 1, 1 do @@ -604,7 +686,6 @@ function Public.create_car(ic, event) local map_name = ic.allowed_surface local entity_type = ic.entity_type - local cars = ic.cars local un = ce.unit_number if not un then @@ -615,12 +696,23 @@ function Public.create_car(ic, event) return end + local name, mined = get_player_entity(ic, player, ce) + + if + name == 'tank' and ce.name == 'car' and not mined or name == 'car' and ce.name == 'car' and not mined or + name == 'car' and ce.name == 'tank' and not mined or + name == 'tank' and ce.name == 'tank' and not mined + then + return player.print('Multiple vehicles are not supported at the moment.', Color.warning) + end + if string.sub(ce.surface.name, 0, #map_name) ~= map_name then return player.print('Multi-surface is not supported at the moment.', Color.warning) end if get_owner_car_name(ic, player) == 'car' and ce.name == 'tank' then upgrade_surface(ic, player, ce) + render_owner_text(player, ce) player.print('Your car-surface has been upgraded!', Color.success) return end @@ -630,13 +722,6 @@ function Public.create_car(ic, event) return end - for _, c in pairs(cars) do - if c.owner == player.index then - ce.destroy() - return player.print('You already have a portable vehicle.', Color.warning) - end - end - local car_areas = ic.car_areas local car_area = car_areas[ce.name] @@ -655,6 +740,7 @@ function Public.create_car(ic, event) car.surface = Public.create_room_surface(ic, un) Public.create_car_room(ic, car) + render_owner_text(player, ce) return car end @@ -681,6 +767,90 @@ function Public.remove_invalid_cars(ic) end end +function Public.infinity_scrap(ic, event, recreate) + if not ic.infinity_scrap_enabled then + return + end + + local entity = event.entity + if not entity or not entity.valid then + return + end + local player = game.players[event.player_index] + if not validate_player(player) then + return + end + + event.buffer.clear() + + if not is_owner_on_car_surface(ic, player) then + if get_player_surface(ic, player) then + entity.surface.create_entity({name = 'sand-rock-big', position = entity.position}) + player.print('This is not your rock to mine!', Color.warning) + return + end + end + + if recreate then + entity.surface.create_entity({name = 'sand-rock-big', position = entity.position}) + return + end + + local items = { + 'iron-plate', + 'iron-gear-wheel', + 'copper-plate', + 'copper-cable', + 'pipe', + 'explosives', + 'firearm-magazine', + 'stone-brick' + } + + local ores = { + 'iron-ore', + 'iron-ore', + 'copper-ore', + 'coal' + } + + local reward + local size + local count + if random(1, 2) == 1 then + reward = items + size = #items + count = random(1, 10) + else + reward = ores + size = #ores + count = random(25, 100) + end + + local name = reward[random(1, size)] + + if entity.name ~= 'sand-rock-big' then + return + end + if get_player_surface(ic, player) then + if entity.position.x == 0 and entity.position.y == 20 or entity.position.y == 40 then + entity.surface.create_entity({name = 'sand-rock-big', position = entity.position}) + player.insert({name = name, count = count}) + if random(1, 4) == 1 then + player.insert({name = 'coin', count = 1}) + end + player.surface.create_entity( + { + name = 'flying-text', + position = entity.position, + text = '+' .. count .. ' [img=item/' .. name .. ']', + color = {r = 0, g = 127, b = 33} + } + ) + end + end +end + function Public.teleport_players_around(ic) for _, player in pairs(game.connected_players) do if not validate_player(player) then diff --git a/maps/mountain_fortress_v3/ic/main.lua b/maps/mountain_fortress_v3/ic/main.lua index 1abd746d..f913b93e 100644 --- a/maps/mountain_fortress_v3/ic/main.lua +++ b/maps/mountain_fortress_v3/ic/main.lua @@ -1,3 +1,5 @@ +require 'modules.check_fullness' + local Event = require 'utils.event' local Functions = require 'maps.mountain_fortress_v3.ic.functions' local IC = require 'maps.mountain_fortress_v3.ic.table' @@ -12,12 +14,15 @@ local function on_entity_died(event) return end - if not entity.type == 'car' then - return + local ic = IC.get() + + if entity.type == 'car' then + Functions.kill_car(ic, entity) end - local ic = IC.get() - Functions.kill_car(ic, entity) + if entity.name == 'sand-rock-big' then + Functions.infinity_scrap(ic, entity, true) + end end local function on_player_mined_entity(event) @@ -26,17 +31,15 @@ local function on_player_mined_entity(event) return end - if not entity.type == 'car' then - return - end - - local player = game.players[event.player_index] - if not player or not player.valid then - return - end - local ic = IC.get() - Functions.save_car(ic, event) + + if entity.type == 'car' then + Functions.save_car(ic, event) + end + + if entity.name == 'sand-rock-big' then + Functions.infinity_scrap(ic, event) + end end local function on_robot_mined_entity(event) @@ -45,13 +48,15 @@ local function on_robot_mined_entity(event) if not entity and not entity.valid then return end + local ic = IC.get() - if not entity.type == 'car' then - return + if entity.type == 'car' then + Functions.kill_car(ic, entity) end - local ic = IC.get() - Functions.kill_car(ic, entity) + if entity.name == 'sand-rock-big' then + Functions.infinity_scrap(ic, event, true) + end end local function on_built_entity(event) @@ -78,6 +83,7 @@ local function on_player_driving_changed_state(event) local player = game.players[event.player_index] Functions.use_door_with_entity(ic, player, event.entity) + Functions.validate_owner(ic, player, event.entity) end local function on_tick() diff --git a/maps/mountain_fortress_v3/ic/table.lua b/maps/mountain_fortress_v3/ic/table.lua index e73ec11c..4ab24b2b 100644 --- a/maps/mountain_fortress_v3/ic/table.lua +++ b/maps/mountain_fortress_v3/ic/table.lua @@ -29,6 +29,7 @@ function Public.reset() this.allowed_surface = 'nauvis' this.players = {} this.surfaces = {} + this.infinity_scrap_enabled = true this.entity_type = { ['car'] = true, ['tank'] = true diff --git a/maps/mountain_fortress_v3/icw/functions.lua b/maps/mountain_fortress_v3/icw/functions.lua index 4fb2eaba..6e26169a 100644 --- a/maps/mountain_fortress_v3/icw/functions.lua +++ b/maps/mountain_fortress_v3/icw/functions.lua @@ -2,6 +2,8 @@ local Public = {} local ICW = require 'maps.mountain_fortress_v3.icw.table' +local random = math.random + local rock_raffle = { 'sand-rock-big', 'sand-rock-big', @@ -429,13 +431,13 @@ function Public.create_wagon_room(icw, wagon) end end - -- for x = -35, 30, 1 do - -- for y = -5, 45, 1 do - -- if math.random(1, 4) == 1 then - -- fishes[#fishes + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = {x, y}} - -- end - -- end - -- end + for x = area.left_top.x, area.right_bottom.x - 1, 1 do + for y = area.left_top.y + 2, area.right_bottom.y - 3, 1 do + if random(1, 16) == 1 then + fishes[#fishes + 1] = {name = rock_raffle[random(1, size_of_rock_raffle)], position = {x, y}} + end + end + end surface.set_tiles(tiles, true) @@ -469,13 +471,6 @@ function Public.create_wagon_room(icw, wagon) return end - -- this.wagon_areas = { - -- ['cargo-wagon'] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 60}}, - -- ['artillery-wagon'] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 60}}, - -- ['fluid-wagon'] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 60}}, - -- ['locomotive'] = {left_top = {x = -20, y = 0}, right_bottom = {x = 20, y = 60}} - -- } - if wagon.entity.type == 'cargo-wagon' then local multiple_chests = ICW.get('multiple_chests') local wagon_areas = ICW.get('wagon_areas') @@ -616,6 +611,57 @@ function Public.create_wagon_room(icw, wagon) end end +function Public.locomotive_mining(icw, event) + local entity = event.entity + if not entity or not entity.valid then + return + end + local player = game.players[event.player_index] + if not validate_player(player) then + return + end + + event.buffer.clear() + + local items = { + 'iron-plate', + 'iron-gear-wheel', + 'copper-plate', + 'copper-cable', + 'pipe', + 'explosives', + 'firearm-magazine', + 'stone-brick' + } + + local reward = items + local size = #items + local count = random(1, 20) + local name = reward[random(1, size)] + + for k, surface in pairs(icw.surfaces) do + if validate_entity(surface) then + if player.surface.index == surface.index then + if entity.type ~= 'simple-entity' then + return + end + player.insert({name = name, count = count}) + if random(1, 4) == 1 then + player.insert({name = 'coin', count = 1}) + end + player.surface.create_entity( + { + name = 'flying-text', + position = entity.position, + text = '+' .. count .. ' [img=item/' .. name .. ']', + color = {r = 0, g = 127, b = 33} + } + ) + end + end + end +end + function Public.create_wagon(icw, created_entity, delay_surface) if not validate_entity(created_entity) then return diff --git a/maps/mountain_fortress_v3/icw/main.lua b/maps/mountain_fortress_v3/icw/main.lua index 78ed4d31..164a8753 100644 --- a/maps/mountain_fortress_v3/icw/main.lua +++ b/maps/mountain_fortress_v3/icw/main.lua @@ -27,6 +27,12 @@ local function on_player_mined_entity(event) return end local icw = ICW.get() + + Functions.locomotive_mining(icw, event) + + if not icw.allow_player_to_build_trains then + return + end Functions.subtract_wagon_entity_count(icw, entity) Functions.kill_wagon(icw, entity) end @@ -37,12 +43,18 @@ local function on_robot_mined_entity(event) return end local icw = ICW.get() + if not icw.allow_player_to_build_trains then + return + end Functions.subtract_wagon_entity_count(icw, entity) Functions.kill_wagon(icw, entity) end local function on_built_entity(event) local icw = ICW.get() + if not icw.allow_player_to_build_trains then + return + end local created_entity = event.created_entity Functions.create_wagon(icw, created_entity) Functions.add_wagon_entity_count(icw, created_entity) @@ -50,6 +62,9 @@ end local function on_robot_built_entity(event) local icw = ICW.get() + if not icw.allow_player_to_build_trains then + return + end local created_entity = event.created_entity Functions.create_wagon(icw, created_entity) Functions.add_wagon_entity_count(icw, created_entity) diff --git a/maps/mountain_fortress_v3/icw/table.lua b/maps/mountain_fortress_v3/icw/table.lua index 045fb6de..7539c829 100644 --- a/maps/mountain_fortress_v3/icw/table.lua +++ b/maps/mountain_fortress_v3/icw/table.lua @@ -27,6 +27,7 @@ function Public.reset() this.players = {} this.surfaces = {} this.multiple_chests = true + this.allow_player_to_build_trains = false this.wagon_types = { ['cargo-wagon'] = true, ['artillery-wagon'] = true, diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index dfb9984f..34d05058 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -1952,7 +1952,7 @@ function Public.transfer_pollution() local active_surface_index = WPT.get('active_surface_index') local icw_locomotive = WPT.get('icw_locomotive') local surface = icw_locomotive.surface - if not surface then + if not surface or not surface.valid then return end @@ -1974,7 +1974,7 @@ function Public.enable_poison_defense() end local pos = locomotive.position create_poison_cloud({x = pos.x, y = pos.y}) - if random(1, 3) == 1 then + if random(1, 4) == 1 then local random_angles = {rad(random(359))} create_poison_cloud({x = pos.x + 24 * cos(random_angles[1]), y = pos.y + -24 * sin(random_angles[1])}) end diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index 5e921ec1..1b81019e 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -50,11 +50,22 @@ local AntiGrief = require 'antigrief' local Public = {} local floor = math.floor -local insert = table.insert +local random = math.random +local tile_damage = 50 -- local raise_event = script.raise_event local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16, ['explosives'] = 32} +local death_messages = { + 'should have watched where they walked!', + 'was not careful enough!', + 'angered the overlords!', + 'tried to walk the simple path!', + 'melted away!', + 'got obliterated!', + 'tried to cheat their way north!' +} + local disable_recipes = function() local force = game.forces.player force.recipes['cargo-wagon'].enabled = false @@ -66,6 +77,24 @@ local disable_recipes = function() force.recipes['pistol'].enabled = false end +local show_text = function(msg, pos, color, surface) + if color == nil then + surface.create_entity({name = 'flying-text', position = pos, text = msg}) + else + surface.create_entity({name = 'flying-text', position = pos, text = msg, color = color}) + end +end + +local init_new_force = function() + local new_force = game.forces.protectors + local enemy = game.forces.enemy + if not new_force then + new_force = game.create_force('protectors') + end + new_force.set_friend('enemy', true) + enemy.set_friend('protectors', true) +end + local collapse_kill = { entities = { ['laser-turret'] = true, @@ -76,6 +105,7 @@ local collapse_kill = { ['locomotive'] = true, ['cargo-wagon'] = true, ['car'] = true, + ['tank'] = true, ['assembling-machine'] = true, ['furnace'] = true, ['steel-chest'] = true @@ -144,48 +174,6 @@ local set_difficulty = function() end end -local biter_settings = function() - -- -- biter settings - if WPT.get('enable_biter_settings') then - local Diff = Difficulty.get() - if not Diff.difficulty_vote_value then - Diff.difficulty_vote_value = 0.1 - end - local plus = ((game.forces.enemy.evolution_factor * 100) + 50) / (77 - Diff.difficulty_vote_value * 2) - local sub = (((1 - game.forces.enemy.evolution_factor) * 100) + 50) / (73 + Diff.difficulty_vote_value * 2) - local enemy_expansion = game.map_settings.enemy_expansion - local unit_group = game.map_settings.unit_group - local path_finder = game.map_settings.path_finder - unit_group.max_wait_time_for_late_members = 3600 * plus - unit_group.max_member_speedup_when_behind = 3 * plus - unit_group.member_disown_distance = 20 * plus - unit_group.max_gathering_unit_groups = 10 * plus - path_finder.max_work_done_per_tick = 6000 * plus - path_finder.max_steps_worked_per_tick = 20 + (100 * plus) - if path_finder.max_steps_worked_per_tick > 2000 then - path_finder.max_steps_worked_per_tick = 200 - end - enemy_expansion.building_coefficient = 0.1 * sub - enemy_expansion.other_base_coefficient = 2.0 * sub - enemy_expansion.neighbouring_chunk_coefficient = 0.5 * sub - enemy_expansion.neighbouring_base_chunk_coefficient = 0.4 * sub - enemy_expansion.max_expansion_distance = 20 * plus - if enemy_expansion.max_expansion_distance > 20 then - enemy_expansion.max_expansion_distance = 20 - end - enemy_expansion.friendly_base_influence_radius = 8 * plus - enemy_expansion.enemy_building_influence_radius = 3 * plus - enemy_expansion.settler_group_min_size = 5 * plus - if enemy_expansion.settler_group_min_size < 1 then - enemy_expansion.settler_group_min_size = 1 - end - enemy_expansion.settler_group_max_size = 20 * plus - if enemy_expansion.settler_group_max_size > 50 then - enemy_expansion.settler_group_max_size = 50 - end - end -end - local render_direction = function(surface) local counter = WPT.get('soft_reset_counter') if counter then @@ -320,6 +308,7 @@ function Public.reset_map() Group.alphanumeric_only(false) disable_tech() + init_new_force() local surface = game.surfaces[this.active_surface_index] @@ -394,8 +383,6 @@ function Public.reset_map() Task.start_queue() Task.set_queue_speed(32) - -- biter_settings() - this.chunk_load_tick = game.tick + 1200 this.game_lost = false @@ -420,6 +407,31 @@ local on_player_changed_position = function(event) local position = player.position local surface = game.surfaces[this.active_surface_index] + if not player.character then + return + end + if not player.character.valid then + return + end + + local p = {x = player.position.x, y = player.position.y} + local get_tile = surface.get_tile(p) + + if get_tile.valid and get_tile.name == 'lab-dark-2' then + if random(1, 2) == 1 then + if random(1, 2) == 1 then + show_text('This path is not for players!', p, {r = 0.98, g = 0.66, b = 0.22}, surface) + end + player.surface.create_entity({name = 'fire-flame', position = player.position}) + player.character.health = player.character.health - tile_damage + if player.character.health == 0 then + player.character.die() + local message = player.name .. ' ' .. death_messages[random(1, #death_messages)] + game.print(message, {r = 0.98, g = 0.66, b = 0.22}) + end + end + end + if position.y >= 74 then player.teleport({position.x, position.y - 1}, surface) player.print('Forcefield does not approve.', {r = 0.98, g = 0.66, b = 0.22}) @@ -840,11 +852,6 @@ local on_tick = function() local update_gui = Gui_mf.update_gui local tick = game.tick - -- if tick % 36000 == 0 then - if tick % 360 == 0 then - biter_settings() - end - if tick % 60 == 0 then for _, player in pairs(game.connected_players) do update_gui(player) diff --git a/maps/mountain_fortress_v3/mining.lua b/maps/mountain_fortress_v3/mining.lua index 1ad01ad2..06c77e08 100644 --- a/maps/mountain_fortress_v3/mining.lua +++ b/maps/mountain_fortress_v3/mining.lua @@ -1,4 +1,5 @@ local WPT = require 'maps.mountain_fortress_v3.table' +require 'modules.check_fullness' local Public = {} local random = math.random @@ -13,6 +14,15 @@ local valid_rocks = { ['rock-huge'] = true } +local valid_trees = { + ['dry-tree'] = true, + ['tree-01'] = true, + ['tree-02-red'] = true, + ['tree-03'] = true, + ['tree-04'] = true, + ['tree-08-brown'] = true +} + local rock_yield = { ['rock-big'] = 1, ['rock-huge'] = 2, @@ -31,6 +41,8 @@ local function create_particles(surface, name, position, amount, cause_position) local d1 = (-100 + random(0, 200)) * 0.0004 local d2 = (-100 + random(0, 200)) * 0.0004 + name = name or 'leaf-particle' + if cause_position then d1 = (cause_position.x - position.x) * 0.025 d2 = (cause_position.y - position.y) * 0.025 @@ -56,12 +68,6 @@ local function create_particles(surface, name, position, amount, cause_position) end end -local function compute_fullness(player) - local free_slots = player.get_main_inventory().count_empty_stacks() - - return free_slots -end - local function mining_chances_ores() local data = { {name = 'iron-ore', chance = 545}, @@ -86,7 +92,7 @@ local function get_amount(data) local entity = data.entity local this = data.this local distance_to_center = floor(sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)) - local type_modifier + local type_modifier = 1 local amount local second_amount @@ -140,49 +146,29 @@ function Public.entity_died_randomness(data) create_particles(surface, particle, position, 64, {x = entity.position.x, y = entity.position.y}) end -local function debug_print(str) - local debug = WPT.get('debug') - if debug then - print(str) - end -end - local function randomness(data) local entity = data.entity local player = data.player local this = data.this - local fullness_enabled = this.fullness_enabled local harvest local harvest_amount - local fullness = compute_fullness(player) - if not fullness_enabled then - goto continue + local n = entity.name + if n == 'tree-08-brown' then + harvest = 'stone' + elseif n == 'tree-04' then + harvest = 'coal' + elseif n == 'tree-02-red' then + harvest = 'copper-ore' + elseif n == 'tree-01' then + harvest = 'iron-ore' + elseif n == 'tree-03' then + harvest = 'coal' + elseif n == 'dry-tree' then + harvest = 'wood' + else + harvest = harvest_raffle_ores[random(1, size_of_ore_raffle)] end - - debug_print(player.name .. ' is ' .. fullness .. '% full.') - - if fullness == 0 then - if player.character then - player.character.health = player.character.health - random(50, 100) - player.character.surface.create_entity({name = 'water-splash', position = player.position}) - local messages = { - 'Ouch.. That hurt! Better be careful now.', - 'Just a fleshwound.', - 'Better keep those hands to yourself or you might loose them.' - } - player.print(messages[random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0}) - if player.character.health <= 0 then - player.character.die('enemy') - game.print(player.name .. ' should have emptied their pockets.', {r = 0.75, g = 0.0, b = 0.0}) - return - end - end - end - - ::continue:: - - harvest = harvest_raffle_ores[random(1, size_of_ore_raffle)] harvest_amount = get_amount(data) local position = {x = entity.position.x, y = entity.position.y} @@ -228,25 +214,25 @@ function Public.on_player_mined_entity(event) if not entity.valid then return end - if not valid_rocks[entity.name] then - return - end local player = game.players[event.player_index] - local this = WPT.get() - if not player then + if not player or not player.valid then return end - event.buffer.clear() + local this = WPT.get() - local data = { - this = this, - entity = entity, - player = player - } + if valid_rocks[entity.name] or valid_trees[entity.name] then + event.buffer.clear() - randomness(data) + local data = { + this = this, + entity = entity, + player = player + } + + randomness(data) + end end return Public diff --git a/maps/mountain_fortress_v3/resource_generator.lua b/maps/mountain_fortress_v3/resource_generator.lua index 1e0eb807..b55298d7 100644 --- a/maps/mountain_fortress_v3/resource_generator.lua +++ b/maps/mountain_fortress_v3/resource_generator.lua @@ -425,7 +425,7 @@ local function spawn_science_buildings(entities, p, probability) entities[#entities + 1] = { name = science_list[probability].name, position = p, - force = 'player', + force = 'neutral', callback = science_list[probability].callback, collision = true, e_type = types @@ -436,7 +436,7 @@ local function spawn_ammo_building(entities, p, probability) entities[#entities + 1] = { name = ammo_list[probability].name, position = p, - force = 'player', + force = 'neutral', callback = ammo_list[probability].callback, collision = true, e_type = types @@ -447,7 +447,7 @@ local function spawn_oil_buildings(entities, p) entities[#entities + 1] = { name = oil_list[1].name, position = p, - force = 'player', + force = 'neutral', callback = oil_list[1].callback, collision = true, e_type = types @@ -458,7 +458,7 @@ local function spawn_oil_prod_buildings(entities, p) entities[#entities + 1] = { name = oil_prod_list[1].name, position = p, - force = 'player', + force = 'neutral', callback = oil_prod_list[1].callback, collision = true, e_type = types @@ -469,7 +469,7 @@ local function spawn_resource_building(entities, p, probability) entities[#entities + 1] = { name = resource_list[probability].name, position = p, - force = 'player', + force = 'neutral', callback = resource_list[probability].callback, collision = true, e_type = types @@ -480,7 +480,7 @@ local function spawn_furnace_building(entities, p, probability) entities[#entities + 1] = { name = furnace_list[probability].name, position = p, - force = 'player', + force = 'neutral', callback = furnace_list[probability].callback, collision = true, e_type = types diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index 8a99eb68..f6342ec2 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -15,7 +15,13 @@ Public.level_depth = 704 Public.level_width = 512 local worm_level_modifier = 0.19 -local wagon_raffle = {'cargo-wagon', 'cargo-wagon', 'cargo-wagon', 'locomotive', 'fluid-wagon'} +local wagon_raffle = { + 'cargo-wagon', + 'cargo-wagon', + 'cargo-wagon', + 'locomotive', + 'fluid-wagon' +} local rock_raffle = { 'sand-rock-big', 'sand-rock-big', @@ -32,10 +38,19 @@ local rock_raffle = { local size_of_rock_raffle = #rock_raffle -local tree_raffle = {'tree-01', 'tree-02-red', 'tree-04', 'tree-08-brown'} +local tree_raffle = { + 'dry-tree', + 'tree-01', + 'tree-02-red', + 'tree-04', + 'tree-08-brown' +} local size_of_tree_raffle = #tree_raffle -local spawner = {'biter-spawner', 'spitter-spawner'} +local spawner = { + 'biter-spawner', + 'spitter-spawner' +} local size_of_spawner = #spawner local scrap_entities = { @@ -62,8 +77,21 @@ local scrap_entities = { local scrap_entities_index = #scrap_entities -local spawner_raffle = {'biter-spawner', 'biter-spawner', 'biter-spawner', 'spitter-spawner'} -local trees = {'tree-08-red', 'tree-02-red', 'tree-06-brown'} +local spawner_raffle = { + 'biter-spawner', + 'biter-spawner', + 'biter-spawner', + 'spitter-spawner' +} + +local trees = { + 'tree-08-brown', + 'tree-04', + 'tree-03', + 'tree-02-red', + 'tree-01', + 'dry-tree' +} local firearm_magazine_ammo = Functions.firearm_magazine_ammo local piercing_rounds_magazine_ammo = Functions.piercing_rounds_magazine_ammo @@ -407,6 +435,15 @@ local function process_level_14_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + if small_caves > -0.41 and small_caves < 0.41 then if noise_cave_ponds > 0.35 then local success = place_wagon(data) @@ -467,6 +504,15 @@ local function process_level_13_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + if small_caves < -0.35 or small_caves > 0.35 then tiles[#tiles + 1] = {name = 'deepwater-green', position = p} if random(1, 128) == 1 then @@ -546,6 +592,15 @@ local function process_level_12_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + if noise_1 < -0.72 then local success = place_wagon(data) if success then @@ -595,7 +650,7 @@ local function process_level_12_position(x, y, data) } end - tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} + tiles[#tiles + 1] = {name = 'tutorial-grid', position = p} end local function process_level_11_position(x, y, data) @@ -632,6 +687,15 @@ local function process_level_11_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + if noise_1 > -0.30 and noise_1 < 0.30 then if noise_1 > -0.14 and noise_1 < 0.14 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} @@ -666,7 +730,32 @@ local function process_level_11_position(x, y, data) return end - tiles[#tiles + 1] = {name = 'tutorial-grid', position = p} + local noise_forest_location = get_noise('forest_location', p, seed) + if noise_forest_location > 0.095 then + if noise_forest_location > 0.6 then + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'red-refined-concrete', position = p} + end + else + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'green-refined-concrete', position = p} + end + end + return + end + + if noise_forest_location < -0.095 then + if noise_forest_location < -0.6 then + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'blue-refined-concrete', position = p} + end + else + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'red-refined-concrete', position = p} + end + end + return + end end local function process_level_10_position(x, y, data) @@ -693,6 +782,15 @@ local function process_level_10_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + --Resource Spots if smol_areas < -0.72 then if random(1, 8) == 1 then @@ -723,13 +821,48 @@ local function process_level_10_position(x, y, data) tiles[#tiles + 1] = {name = 'water-shallow', position = p} return end + local noise_forest_location = get_noise('forest_location', p, seed) if scrapyard > -0.15 and scrapyard < 0.15 then - if random(1, 100) > 88 then - entities[#entities + 1] = {name = 'tree-0' .. random(1, 9), position = p} - else - if random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[random(1, size_of_rock_raffle)], position = p} + if noise_forest_location > 0.095 then + if random(1, 256) == 1 then + Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier) + entities[#entities + 1] = { + name = Biters.wave_defense_roll_worm_name(), + position = p, + force = 'enemy' + } end + if noise_forest_location > 0.6 then + if random(1, 100) > 42 then + entities[#entities + 1] = {name = 'tree-03', position = p} + end + else + if random(1, 100) > 42 then + entities[#entities + 1] = {name = 'tree-01', position = p} + end + end + return + end + + if noise_forest_location < -0.095 then + if random(1, 256) == 1 then + Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier) + entities[#entities + 1] = { + name = Biters.wave_defense_roll_worm_name(), + position = p, + force = 'enemy' + } + end + if noise_forest_location < -0.6 then + if random(1, 100) > 42 then + entities[#entities + 1] = {name = 'dry-tree', position = p} + end + else + if random(1, 100) > 42 then + entities[#entities + 1] = {name = 'tree-02-red', position = p} + end + end + return end tiles[#tiles + 1] = {name = 'dirt-6', position = p} return @@ -783,6 +916,15 @@ local function process_level_9_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + --Resource Spots if smol_areas < -0.72 then if random(1, 8) == 1 then @@ -820,16 +962,25 @@ local function process_level_8_position(x, y, data) local small_caves = get_noise('small_caves', p, seed) if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then if small_caves > 0.35 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.35 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + if scrapyard < -0.25 or scrapyard > 0.25 then if random(1, 256) == 1 then if random(1, 8) == 1 then @@ -998,12 +1149,12 @@ local function process_level_7_position(x, y, data) local small_caves = get_noise('small_caves', p, seed) if noise_cave_ponds < 0.25 and noise_cave_ponds > -0.25 then if small_caves > 0.55 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.55 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end @@ -1043,12 +1194,12 @@ local function process_level_6_position(x, y, data) local small_caves = get_noise('small_caves', p, seed) if noise_cave_ponds < 0.45 and noise_cave_ponds > -0.45 then if small_caves > 0.45 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.45 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end end @@ -1061,13 +1212,22 @@ local function process_level_6_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + --Resource Spots if smol_areas < -0.72 then if random(1, 8) == 1 then Generate_resources(buildings, p, Public.level_depth) end end - + local noise_forest_location = get_noise('forest_location', p, seed) if cave_rivers > -0.1 and cave_rivers < 0.1 then local success = place_wagon(data) if success then @@ -1086,7 +1246,47 @@ local function process_level_6_position(x, y, data) else tiles[#tiles + 1] = {name = 'dirt-7', position = p} if random(1, 100) > 15 then - entities[#entities + 1] = {name = rock_raffle[random(1, size_of_rock_raffle)], position = p} + if noise_forest_location > 0.095 then + if random(1, 256) == 1 then + Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier) + entities[#entities + 1] = { + name = Biters.wave_defense_roll_worm_name(), + position = p, + force = 'enemy' + } + end + if noise_forest_location > 0.6 then + if random(1, 100) > 42 then + entities[#entities + 1] = {name = 'tree-08-brown', position = p} + end + else + if random(1, 100) > 42 then + entities[#entities + 1] = {name = 'tree-01', position = p} + end + end + return + end + + if noise_forest_location < -0.095 then + if random(1, 256) == 1 then + Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier) + entities[#entities + 1] = { + name = Biters.wave_defense_roll_worm_name(), + position = p, + force = 'enemy' + } + end + if noise_forest_location < -0.6 then + if random(1, 100) > 42 then + entities[#entities + 1] = {name = 'tree-04', position = p} + end + else + if random(1, 100) > 42 then + entities[#entities + 1] = {name = 'tree-02-red', position = p} + end + end + return + end end if random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} @@ -1145,6 +1345,15 @@ local function process_level_5_position(x, y, data) end end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + if small_caves > -0.40 and small_caves < 0.40 then if noise_cave_ponds > 0.35 then local success = place_wagon(data) @@ -1171,7 +1380,7 @@ local function process_level_5_position(x, y, data) end end - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} end local function process_level_4_position(x, y, data) @@ -1235,12 +1444,12 @@ local function process_level_4_position(x, y, data) --Chasms if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then if small_caves > 0.75 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.75 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end end @@ -1284,7 +1493,7 @@ local function process_level_4_position(x, y, data) return end - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} end local function process_level_3_position(x, y, data) @@ -1326,6 +1535,15 @@ local function process_level_3_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + if noise_large_caves > -0.15 and noise_large_caves < 0.15 or small_caves_2 > 0 then --Green Water Ponds if noise_cave_ponds > 0.80 then @@ -1339,13 +1557,13 @@ local function process_level_3_position(x, y, data) --Chasms if noise_cave_ponds < 0.12 and noise_cave_ponds > -0.12 then if small_caves > 0.85 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.85 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end @@ -1431,7 +1649,7 @@ local function process_level_3_position(x, y, data) return end - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} end local function process_level_2_position(x, y, data) @@ -1460,12 +1678,12 @@ local function process_level_2_position(x, y, data) --Chasms if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then if small_caves > 0.32 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.32 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end end @@ -1496,6 +1714,15 @@ local function process_level_2_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + --Market Spots if noise_cave_ponds < -0.80 then tiles[#tiles + 1] = {name = 'grass-' .. floor(noise_cave_ponds * 32) % 3 + 1, position = p} @@ -1561,7 +1788,7 @@ local function process_level_2_position(x, y, data) return end - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} end local function process_level_1_2_position(x, y, data) @@ -1587,11 +1814,11 @@ local function process_level_1_2_position(x, y, data) --Chasms if noise_cave_ponds < 0.101 and noise_cave_ponds > -0.102 then if small_caves > 0.52 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.52 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end end @@ -1617,12 +1844,13 @@ local function process_level_1_2_position(x, y, data) end end - if random(1, 512) == 1 then + if random(1, 2048) == 1 then entities[#entities + 1] = { name = spawner[random(1, size_of_spawner)], position = p, - force = 'enemy' + force = 'protectors' } + return end if noise_cave_ponds > 0.74 then @@ -1701,7 +1929,7 @@ local function process_level_1_2_position(x, y, data) tiles[#tiles + 1] = {name = 'grass-' .. floor(noise_cave_ponds * 32) % 3 + 1, position = p} local noise_forest_location = get_noise('forest_location', p, seed) if noise_forest_location > 0.095 then - if random(1, 96) == 1 then + if random(1, 256) == 1 then Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier) entities[#entities + 1] = { name = Biters.wave_defense_roll_worm_name(), @@ -1722,14 +1950,13 @@ local function process_level_1_2_position(x, y, data) end if noise_forest_location < -0.095 then - if random(1, 96) == 1 then + if random(1, 256) == 1 then Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier) entities[#entities + 1] = { name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy' } - end if noise_forest_location < -0.6 then if random(1, 100) > 42 then @@ -1767,11 +1994,11 @@ local function process_level_1_position(x, y, data) --Chasms if noise_cave_ponds < 0.111 and noise_cave_ponds > -0.112 then if small_caves > 0.53 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.53 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end end @@ -1785,6 +2012,15 @@ local function process_level_1_position(x, y, data) return end + if random(1, 2048) == 1 then + entities[#entities + 1] = { + name = spawner[random(1, size_of_spawner)], + position = p, + force = 'protectors' + } + return + end + --Rivers local cave_rivers = get_noise('cave_rivers', p, seed + 300000) if cave_rivers < 0.042 and cave_rivers > -0.042 then @@ -1870,7 +2106,30 @@ local function process_level_1_position(x, y, data) if random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'iron-chest'} end - tiles[#tiles + 1] = {name = 'dirt-7', position = p} + local random_tiles = get_noise('forest_location', p, seed) + if random_tiles > 0.095 then + if random_tiles > 0.6 then + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'sand-1', position = p} + end + else + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'sand-2', position = p} + end + end + end + + if random_tiles < -0.095 then + if random_tiles < -0.6 then + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'sand-1', position = p} + end + else + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'lab-dark-1', position = p} + end + end + end if random(1, 100) > 25 then entities[#entities + 1] = {name = rock_raffle[random(1, size_of_rock_raffle)], position = p} end @@ -1899,11 +2158,11 @@ local function process_level_0_position(x, y, data) --Chasms if noise_cave_ponds < 0.101 and noise_cave_ponds > -0.102 then if small_caves > 0.52 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end if small_caves < -0.52 then - tiles[#tiles + 1] = {name = 'out-of-map', position = p} + tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} return end end @@ -2002,9 +2261,32 @@ local function process_level_0_position(x, y, data) if random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'iron-chest'} end - tiles[#tiles + 1] = {name = 'grass-' .. floor(noise_cave_ponds * 32) % 3 + 1, position = p} + local random_tiles = get_noise('forest_location', p, seed) + if random_tiles > 0.095 then + if random_tiles > 0.6 then + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'red-desert-0', position = p} + end + else + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'red-desert-1', position = p} + end + end + end + + if random_tiles < -0.095 then + if random_tiles < -0.6 then + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'red-desert-2', position = p} + end + else + if random(1, 100) > 42 then + tiles[#tiles + 1] = {name = 'red-desert-3', position = p} + end + end + end if random(1, 100) > 25 then - if random(1, 20) == 2 then + if random(1, 10) == 1 then entities[#entities + 1] = {name = tree_raffle[random(1, size_of_tree_raffle)], position = p} else entities[#entities + 1] = {name = rock_raffle[random(1, size_of_rock_raffle)], position = p} @@ -2018,6 +2300,8 @@ Public.levels = { process_level_1_position, process_level_3_position, process_level_5_position, + process_level_8_position, + process_level_9_position, process_level_4_position, process_level_6_position, process_level_2_position, @@ -2045,7 +2329,7 @@ end local function process_bits(x, y, data) local levels = Public.levels local left_top_y = data.area.left_top.y - local index = floor((abs(left_top_y / Public.level_depth)) % 20) + 1 + local index = floor((abs(left_top_y / Public.level_depth)) % 22) + 1 local process_level = levels[index] if not process_level then process_level = levels[#levels] diff --git a/modules/check_fullness.lua b/modules/check_fullness.lua new file mode 100644 index 00000000..21154daa --- /dev/null +++ b/modules/check_fullness.lua @@ -0,0 +1,81 @@ +local Global = require 'utils.global' +local Event = require 'utils.event' + +local this = { + fullness_enabled = true +} + +Global.register( + this, + function(t) + this = t + end +) + +local Public = {} +local random = math.random + +local function compute_fullness(player) + local free_slots = player.get_main_inventory().count_empty_stacks() + if free_slots == 0 then + if player.character then + player.character.health = player.character.health - random(50, 100) + player.character.surface.create_entity({name = 'water-splash', position = player.position}) + local messages = { + 'Ouch.. That hurt! Better be careful now.', + 'Just a fleshwound.', + 'Better keep those hands to yourself or you might loose them.' + } + player.print(messages[random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0}) + if player.character.health <= 0 then + player.character.die('enemy') + game.print(player.name .. ' should have emptied their pockets.', {r = 0.75, g = 0.0, b = 0.0}) + return free_slots + end + end + end + return free_slots +end + +function Public.check_fullness(player) + if this.fullness_enabled then + local fullness = compute_fullness(player) + if fullness == 0 then + return + end + end +end + +function Public.enable_fullness(value) + if value then + this.fullness_enabled = value + else + this.fullness_enabled = false + end + return this.fullness_enabled +end + +local check_fullness = Public.check_fullness + +Event.add( + defines.events.on_player_mined_entity, + function(event) + local entity = event.entity + if not entity or not entity.valid then + return + end + + local player = game.players[event.player_index] + if not player or not player.valid then + return + end + + if not this.fullness_enabled then + return + end + + check_fullness(player) + end +) + +return Public diff --git a/modules/rpg/gui.lua b/modules/rpg/gui.lua index 18c40fba..acde8c91 100644 --- a/modules/rpg/gui.lua +++ b/modules/rpg/gui.lua @@ -24,6 +24,8 @@ local settings_frame_name = RPG.settings_frame_name local discard_button_name = RPG.discard_button_name local save_button_name = RPG.save_button_name +local sub = string.sub + function Public.draw_gui_char_button(player) if player.gui.top[draw_main_frame_name] then return @@ -556,9 +558,10 @@ Gui.on_click( draw_main_frame_name, function(event) local player = event.player - if not player.character then + if not player or not player.valid or not player.character then return end + toggle(player) end ) @@ -567,7 +570,7 @@ Gui.on_click( save_button_name, function(event) local player = event.player - if not player.character then + if not player or not player.valid or not player.character then return end @@ -682,7 +685,7 @@ Gui.on_click( local player = event.player local screen = player.gui.screen local frame = screen[settings_frame_name] - if not player.character then + if not player or not player.valid or not player.character then return end if frame and frame.valid then @@ -697,9 +700,15 @@ Gui.on_click( local player = event.player local screen = player.gui.screen local frame = screen[settings_frame_name] - if not player.character then + if not player or not player.valid or not player.character then return end + + local surface_name = RPG.get('rpg_extra').surface_name + if sub(player.surface.name, 0, #surface_name) ~= surface_name then + return + end + if frame and frame.valid then frame.destroy() else diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index 01aa01a6..a0007cfe 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -20,6 +20,8 @@ local nth_tick = RPG.nth_tick --RPG Frames local main_frame_name = RPG.main_frame_name +local sub = string.sub + local function on_gui_click(event) if not event.element then return @@ -29,6 +31,14 @@ local function on_gui_click(event) end local element = event.element local player = game.players[event.player_index] + if not player or not player.valid then + return + end + + local surface_name = RPG.get('rpg_extra').surface_name + if sub(player.surface.name, 0, #surface_name) ~= surface_name then + return + end if element.type ~= 'sprite-button' then return @@ -469,6 +479,13 @@ local function on_entity_damaged(event) return end + local p = event.cause.player + + local surface_name = RPG.get('rpg_extra').surface_name + if sub(p.surface.name, 0, #surface_name) ~= surface_name then + return + end + Functions.reward_mana(event.cause.player, 2) --Grant the player life-on-hit. @@ -577,9 +594,10 @@ local function on_player_repaired_entity(event) local player = game.players[event.player_index] - if not player.character then + if not player or not player.valid or not player.character then return end + Functions.gain_xp(player, 0.05) Functions.reward_mana(player, 0.2) @@ -592,9 +610,14 @@ end local function on_player_rotated_entity(event) local player = game.players[event.player_index] + + if not player or not player.valid then + return + end if not player.character then return end + local rpg_t = RPG.get('rpg_t') if rpg_t[player.index].rotated_entity_delay > game.tick then return @@ -605,8 +628,7 @@ end local function on_player_changed_position(event) local player = game.players[event.player_index] - local surface_name = RPG.get('rpg_extra').surface_name - if string.sub(player.surface.name, 0, #surface_name) ~= surface_name then + if not player or not player.valid then return end @@ -646,6 +668,16 @@ local function on_pre_player_mined_item(event) return end local player = game.players[event.player_index] + + if not player or not player.valid then + return + end + + local surface_name = RPG.get('rpg_extra').surface_name + if sub(player.surface.name, 0, #surface_name) ~= surface_name then + return + end + local rpg_t = RPG.get('rpg_t') if rpg_t[player.index].last_mined_entity_position.x == event.entity.position.x and @@ -682,7 +714,7 @@ local function on_player_crafted_item(event) return end local player = game.players[event.player_index] - if not player.valid then + if not player or not player.valid then return end @@ -847,7 +879,7 @@ local function on_player_used_capsule(event) return end - if string.sub(player.surface.name, 0, #surface_name) ~= surface_name then + if sub(player.surface.name, 0, #surface_name) ~= surface_name then return end