From e24dc9ee92bd082680048c154ef4bd10a519e681 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 7 Jul 2020 16:30:04 +0200 Subject: [PATCH] mtn fortress fixes --- maps/mountain_fortress_v3/entities.lua | 6 + maps/mountain_fortress_v3/functions.lua | 26 ----- maps/mountain_fortress_v3/gui.lua | 12 ++ maps/mountain_fortress_v3/locomotive.lua | 133 ++++++++++++++++++++--- maps/mountain_fortress_v3/main.lua | 11 +- maps/mountain_fortress_v3/table.lua | 4 +- 6 files changed, 138 insertions(+), 54 deletions(-) diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index 8a6d7297..2d08fae8 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -250,6 +250,7 @@ local function angry_tree(entity, cause) if entity.type ~= 'tree' then return end + if math.abs(entity.position.y) < Terrain.level_depth then return end @@ -338,6 +339,11 @@ local function on_player_mined_entity(event) this.mined_scrap = this.mined_scrap + 1 Mining.on_player_mined_entity(event) give_coin(player) + + if Locomotive.is_around_train(entity) then + return + end + if math.random(1, 32) == 1 then hidden_biter(event.entity) entity.destroy() diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index b47fb026..3847cd71 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -9,8 +9,6 @@ local Public = {} local magic_crafters_per_tick = 3 local magic_fluid_crafters_per_tick = 8 local floor = math.floor -local round = math.round -local table_shuffle_table = table.shuffle_table local function fast_remove(tbl, index) local count = #tbl @@ -196,30 +194,6 @@ local function add_magic_crafter_output(entity, output, distance) end end -function roll(budget, item_name) - if not budget then - return - end - - budget = math.floor(budget) - if budget == 0 then - return - end - - local final_stack_set - local final_stack_set_worth = 0 - - for _ = 1, 5, 1 do - local item_stack_set, item_stack_set_worth = roll_item_stacks(budget, item_name) - if item_stack_set_worth > final_stack_set_worth or item_stack_set_worth == budget then - final_stack_set = item_stack_set - final_stack_set_worth = item_stack_set_worth - end - end - - return final_stack_set -end - local function tick() do_refill_turrets() do_magic_crafters() diff --git a/maps/mountain_fortress_v3/gui.lua b/maps/mountain_fortress_v3/gui.lua index 23ec028c..268feb97 100644 --- a/maps/mountain_fortress_v3/gui.lua +++ b/maps/mountain_fortress_v3/gui.lua @@ -103,6 +103,15 @@ local function create_main_frame(player) label.style.font_color = {r = 0.88, g = 0.88, b = 0.88} label.style.font = 'default-bold' label.style.right_padding = 4 + + line = frame.add({type = 'line', direction = 'vertical'}) + line.style.left_padding = 4 + line.style.right_padding = 4 + + label = frame.add({type = 'label', caption = ' ', name = 'chest_upgrades'}) + label.style.font_color = {r = 0.88, g = 0.88, b = 0.88} + label.style.font = 'default-bold' + label.style.right_padding = 4 end local function on_player_joined_game(event) @@ -288,6 +297,9 @@ function Public.update_gui(player) gui.train_upgrades.caption = ' [img=entity.locomotive]: ' .. format_number(this.train_upgrades, true) gui.train_upgrades.tooltip = 'Amount of train upgrades.' + + gui.chest_upgrades.caption = ' [img=entity.steel-chest]: ' .. format_number(this.chest_limit_outside_upgrades, true) + gui.chest_upgrades.tooltip = 'Amount of chests that can be placed near train.' end Event.add(defines.events.on_player_joined_game, on_player_joined_game) diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index 79d0c4a8..04e68785 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -91,6 +91,22 @@ local function property_boost(data) end end +local function is_around_train(data) + local entity = data.entity + local aura = 60 + local loco = data.locomotive.position + local area = { + left_top = {x = loco.x - aura, y = loco.y - aura}, + right_bottom = {x = loco.x + aura, y = loco.y + aura} + } + local pos = entity.position + + if Math2D.bounding_box.contains_point(area, pos) then + return true + end + return false +end + local function fish_tag() local this = WPT.get() if not this.locomotive_cargo then @@ -636,6 +652,14 @@ local function gui_click(event) local item_count = item.stack * slider_value if name == 'chest_limit_outside' then + if this.chest_limit_outside_upgrades == 8 then + local main_market_items = WPT.get('main_market_items') + + main_market_items['chest_limit_outside'].enabled = false + main_market_items['chest_limit_outside'].tooltip = 'Max limit bought!' + redraw_market_items(data.item_frame, player, data.search_text) + return player.print("You can't purchase more chests.", {r = 0.98, g = 0.66, b = 0.22}) + end player.remove_item({name = item.value, count = item.price}) local message = @@ -1028,6 +1052,7 @@ local function on_built_entity(event) local chests_linked_to = WPT.get('chests_linked_to') local chest_limit_outside_upgrades = WPT.get('chest_limit_outside_upgrades') local chest_created + local increased = false for k, v in pairs(outside_chests) do if v and v.valid then @@ -1037,11 +1062,19 @@ local function on_built_entity(event) return end outside_chests[entity.unit_number] = entity - chests_linked_to[train.unit_number].count = linked_to + 1 + + if not increased then + chests_linked_to[train.unit_number].count = linked_to + 1 + chests_linked_to[train.unit_number][entity.unit_number] = true + increased = true + goto continue + end else outside_chests[entity.unit_number] = entity - chests_linked_to[train.unit_number] = {count = 1, chest = entity.unit_number} + chests_linked_to[train.unit_number] = {count = 1} end + + ::continue:: rendering.draw_text { text = '♠', surface = entity.surface, @@ -1061,7 +1094,9 @@ local function on_built_entity(event) if next(outside_chests) == nil then outside_chests[entity.unit_number] = entity - chests_linked_to[train.unit_number] = {count = 1, chest = entity.unit_number} + chests_linked_to[train.unit_number] = {count = 1} + chests_linked_to[train.unit_number][entity.unit_number] = true + rendering.draw_text { text = '♠', surface = entity.surface, @@ -1087,12 +1122,15 @@ local function on_player_and_robot_mined_entity(event) if outside_chests[entity.unit_number] then for k, v in pairs(chests_linked_to) do - if v.chest == entity.unit_number then + if v[entity.unit_number] then v.count = v.count - 1 if v.count <= 0 then chests_linked_to[k] = nil end end + if chests_linked_to[k] and chests_linked_to[k][entity.unit_number] then + chests_linked_to[k][entity.unit_number] = nil + end end outside_chests[entity.unit_number] = nil end @@ -1170,15 +1208,25 @@ local function add_random_loot_to_main_market(rarity) end for k, v in pairs(items) do - log(serpent.block(items)) + local price = v.price[1][2] + math.random(1, 15) * rarity + local value = v.price[1][1] + local stack = 1 ticker = ticker + 1 + if v.offer.item == 'coin' then + price = v.price[1][2] + stack = v.offer.count + if not stack then + stack = v.price[1][2] + end + end + if main_market_items[v.offer.item] then main_market_items[v.offer.item] = nil end main_market_items[v.offer.item] = { - stack = 1, - value = v.price[1][1], - price = v.price[1][2] + math.random(1, 15) * rarity, + stack = stack, + value = value, + price = price, tooltip = types[v.offer.item].localised_name, upgrade = false } @@ -1189,6 +1237,11 @@ local function add_random_loot_to_main_market(rarity) end local function on_research_finished() + local difficulty_poll_closing_timeout = Difficulty.get('difficulty_poll_closing_timeout') + if game.tick < difficulty_poll_closing_timeout then + return + end + local locomotive = WPT.get('locomotive') if not locomotive or not locomotive.valid then return @@ -1279,6 +1332,36 @@ function Public.boost_players_around_train() property_boost(data) end +function Public.is_around_train(entity) + local locomotive = WPT.get('locomotive') + local active_surface_index = WPT.get('active_surface_index') + + if not active_surface_index then + return false + end + if not locomotive then + return false + end + if not locomotive.valid then + return false + end + + if not entity or not entity.valid then + return false + end + + local surface = game.surfaces[active_surface_index] + + local data = { + locomotive = locomotive, + surface = surface, + entity = entity + } + + local success = is_around_train(data) + return success +end + function Public.render_train_hp() local this = WPT.get() local surface = game.surfaces[this.active_surface_index] @@ -1399,16 +1482,29 @@ function Public.get_items() local land_mine_cost = 2 * (1 + landmine) local skill_reset_cost = 100000 - main_market_items['chest_limit_outside'] = { - stack = 1, - value = 'coin', - price = chest_limit_cost, - tooltip = 'Upgrades the amount of chests that can be placed outside.\nCan be purchased multiple times.', - sprite = 'achievement/getting-on-track', - enabled = true, - upgrade = true, - static = true - } + if main_market_items['chest_limit_outside'] then + main_market_items['chest_limit_outside'] = { + stack = 1, + value = 'coin', + price = chest_limit_cost, + tooltip = main_market_items['chest_limit_outside'].tooltip, + sprite = 'achievement/so-long-and-thanks-for-all-the-fish', + enabled = main_market_items['chest_limit_outside'].enabled, + upgrade = true, + static = true + } + else + main_market_items['chest_limit_outside'] = { + stack = 1, + value = 'coin', + price = chest_limit_cost, + tooltip = 'Upgrades the amount of chests that can be placed outside.\nCan be purchased multiple times.', + sprite = 'achievement/so-long-and-thanks-for-all-the-fish', + enabled = true, + upgrade = true, + static = true + } + end main_market_items['locomotive_max_health'] = { stack = 1, value = 'coin', @@ -1605,6 +1701,7 @@ Event.add(defines.events.on_gui_closed, gui_closed) Event.add(defines.events.on_player_changed_position, on_player_changed_position) Event.add(defines.events.on_research_finished, on_research_finished) Event.add(defines.events.on_built_entity, on_built_entity) +Event.add(defines.events.on_robot_built_entity, on_built_entity) Event.add(defines.events.on_entity_died, on_player_and_robot_mined_entity) Event.add(defines.events.on_pre_player_mined_item, on_player_and_robot_mined_entity) Event.add(defines.events.on_robot_mined_entity, on_player_and_robot_mined_entity) diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index f0e2e5e5..af798eba 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -217,6 +217,8 @@ function Public.reset_map() game.reset_time_played() WPT.reset_table() Map_score.reset_score() + AntiGrief.reset_tables() + RPG.rpg_reset_all_players() disable_tech() @@ -228,18 +230,12 @@ function Public.reset_map() Balance.init_enemy_weapon_damage() - global.bad_fire_history = {} global.custom_highscore.description = 'Wagon distance reached:' Entities.set_scores() - global.friendly_fire_history = {} - global.landfill_history = {} - global.mining_history = {} AntiGrief.log_tree_harvest(true) AntiGrief.whitelist_types('tree', true) get_score.score_table = {} - Diff.difficulty_poll_closing_timeout = game.tick + 90000 - Diff.difficulty_player_votes = {} - Diff.difficulty_poll_closing_timeout = 60000 + Difficulty.reset_difficulty_poll({difficulty_poll_closing_timeout = game.tick + 36000}) Diff.gui_width = 20 Collapse.set_kill_entities(false) @@ -259,7 +255,6 @@ function Public.reset_map() Locomotive.render_train_hp() render_direction(surface) -- LM.place_market() - RPG.rpg_reset_all_players() WD.reset_wave_defense() wave_defense_table.surface_index = this.active_surface_index diff --git a/maps/mountain_fortress_v3/table.lua b/maps/mountain_fortress_v3/table.lua index f3563b78..9f6fe5cf 100644 --- a/maps/mountain_fortress_v3/table.lua +++ b/maps/mountain_fortress_v3/table.lua @@ -9,7 +9,7 @@ local this = { logistic_research_level = 0, reset_counter = 1 }, - power_sources = {}, + power_sources = {index = 1}, refill_turrets = {index = 1}, magic_crafters = {index = 1}, magic_fluid_crafters = {index = 1}, @@ -43,7 +43,7 @@ function Public.reset_table() this.train_upgrades = 0 this.offline_players = {} this.biter_pets = {} - this.power_sources = {} + this.power_sources = {index = 1} this.flamethrower_damage = {} this.refill_turrets = {index = 1} this.magic_crafters = {index = 1}