diff --git a/modules/map_score.lua b/comfy_panel/map_score.lua similarity index 83% rename from modules/map_score.lua rename to comfy_panel/map_score.lua index 100f9d45..744c0f66 100644 --- a/modules/map_score.lua +++ b/comfy_panel/map_score.lua @@ -18,16 +18,6 @@ local score_list = (function (player, frame) frame.style.padding = 4 frame.style.margin = 0 - local line = frame.add { type = "line"} - line.style.top_margin = 4 - line.style.bottom_margin = 4 - - local label = frame.add ({ type = "label", caption = highscore.caption}) - label.style.font = "heading-1" - label.style.minimal_width = 780 - label.style.horizontal_align = "center" - label.style.vertical_align = "center" - local line = frame.add { type = "line"} line.style.top_margin = 4 line.style.bottom_margin = 4 @@ -47,7 +37,7 @@ local score_list = (function (player, frame) label.style.minimal_width = 160 label.style.font = "heading-2" label.style.padding = 3 - local label = t.add ({ type = "label", caption = "Won rounds:"}) + local label = t.add ({ type = "label", caption = global.custom_highscore.description}) label.style.minimal_width = 160 label.style.font = "heading-2" label.style.padding = 3 @@ -67,6 +57,10 @@ local score_list = (function (player, frame) end ) +function Public.set_score_description(str) + global.custom_highscore.description = str +end + function Public.set_score(player, count) local score_list = global.custom_highscore.score_list score_list[player.index] = count @@ -80,12 +74,12 @@ end local function on_init() global.custom_highscore = { - caption = "Highscores of the session:", + description = "Won rounds:", score_list = {}, } end -comfy_panel_tabs["Map Scores"] = score_list +comfy_panel_tabs["Map Scores"] = {gui = score_list, admin = false} local event = require 'utils.event' event.on_init(on_init) diff --git a/maps/biter_hatchery/main.lua b/maps/biter_hatchery/main.lua index efee7d1f..023eba6f 100644 --- a/maps/biter_hatchery/main.lua +++ b/maps/biter_hatchery/main.lua @@ -2,7 +2,7 @@ require "modules.no_turrets" --require "maps.biter_hatchery.flamethrower_nerf" local RPG = require "modules.rpg" local Tabs = require 'comfy_panel.main' -local Map_score = require "modules.map_score" +local Map_score = require "comfy_panel.map_score" local Unit_health_booster = require "modules.biter_health_booster" local unit_raffle = require "maps.biter_hatchery.raffle_tables" local Terrain = require "maps.biter_hatchery.terrain" diff --git a/maps/mountain_fortress_v2/main.lua b/maps/mountain_fortress_v2/main.lua index db5353b2..9ee00516 100644 --- a/maps/mountain_fortress_v2/main.lua +++ b/maps/mountain_fortress_v2/main.lua @@ -7,6 +7,8 @@ require "player_modifiers" require "functions.soft_reset" require "functions.basic_markets" +local ComfyPanel = require "comfy_panel.main" +local Map_score = require "comfy_panel.map_score" local Collapse = require "modules.collapse" local RPG = require "modules.rpg" require "modules.wave_defense.main" @@ -30,7 +32,11 @@ local WD = require "modules.wave_defense.table" local Treasure = require "maps.mountain_fortress_v2.treasure" local Locomotive = require "maps.mountain_fortress_v2.locomotive" local Modifier = require "player_modifiers" + local math_random = math.random +local math_abs = math.abs +local math_floor = math.floor + local Public = {} local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16, ['explosives'] = 32} @@ -48,9 +54,20 @@ local function game_over() global.game_reset_tick = game.tick + 1800 for _, player in pairs(game.connected_players) do player.play_sound{path="utility/game_lost", volume_modifier=0.80} + ComfyPanel.comfy_panel_call_tab(player, "Map Scores") end end +local function set_scores() + local fish_wagon = global.locomotive_cargo + if not fish_wagon then return end + if not fish_wagon.valid then return end + local score = math_floor(fish_wagon.position.y * -1) + for _, player in pairs(game.connected_players) do + if score > Map_score.get_score(player) then Map_score.set_score(player, score) end + end +end + local function disable_recipes() local force = game.forces.player force.recipes["cargo-wagon"].enabled = false @@ -299,8 +316,9 @@ end local function on_entity_died(event) if not event.entity.valid then return end if event.entity == global.locomotive_cargo then + set_scores() game_over() - event.entity.surface.spill_item_stack(event.entity.position,{name = "raw-fish", count = 512}, false) + event.entity.surface.spill_item_stack(event.entity.position,{name = "raw-fish", count = 512}, false) return end @@ -461,6 +479,7 @@ local function tick() if global.offline_loot then offline_players() end + set_scores() end if global.game_reset_tick then if global.game_reset_tick < tick then @@ -491,6 +510,8 @@ local function on_init() ["water-shallow"] = 1000, } + Map_score.set_score_description("Wagon depth reached:") + Public.reset_map() end