Fixed some radar, planet, and dropzone bugs

This commit is contained in:
William Lewis 2026-10-07 15:41:45 -05:00
parent 66c33eb730
commit 0e9e38509e
6 changed files with 62 additions and 11 deletions

View File

@ -36,6 +36,11 @@ script.on_event(defines.events.on_player_died, base.on_player_died)
script.on_event(defines.events.on_pre_player_mined_item, base.on_pre_player_mined_item)
script.on_event(defines.events.on_robot_pre_mined, base.on_robot_pre_mined)
script.on_nth_tick(1800, radar.on_orbital_scan_tick)
-- Fires once on the first tick after any save load, then unregisters itself.
script.on_nth_tick(1, function()
script.on_nth_tick(1, nil)
setup.on_save_loaded()
end)
script.on_event(defines.events.on_cargo_pod_finished_ascending, drop_zone.on_cargo_pod_finished_ascending)
script.on_event(defines.events.on_entity_damaged, drop_zone.on_entity_damaged)
script.on_event(defines.events.on_lua_shortcut, drop_zone.on_lua_shortcut)

View File

@ -1,3 +1,8 @@
-- Both mods define the same prototypes; give a clear error instead of duplicate-name crashes.
if mods["Planet-PvP"] then
error("Planet PvP Green cannot be enabled at the same time as the original Planet-PvP mod. Disable one of them.")
end
data:extend({
{
type = "selection-tool",
@ -83,7 +88,7 @@ data:extend({
{
type = "item",
name = "pvp-base-core",
icon = "__Planet-PvP__/Graphics/Base/base_core.png",
icon = "__Planet-PvP-Green__/Graphics/Base/base_core.png",
icon_size = 128,
subgroup = "other",
order = "z[pvp-base-core]",
@ -135,7 +140,7 @@ data:extend({
{
type = "technology",
name = "planet-discovery-nauvis",
icon = "__Planet-PvP__/Graphics/Tech/nauvis-tech.png",
icon = "__Planet-PvP-Green__/Graphics/Tech/nauvis-tech.png",
icon_size = 210,
essential = true,
effects = {

View File

@ -22,7 +22,9 @@ function drop_zone.on_player_changed_surface(event)
local player = game.players[event.player_index]
if not (player and player.valid) then return end
local surface = player.surface
if event.surface_index == surface.index or surface.platform or player.render_mode == defines.render_mode.chart then return end
-- render_mode is only "game" when physically present; "chart"/"chart_zoomed_out"
-- mean the surface is just being viewed on the map, so don't teleport.
if event.surface_index == surface.index or surface.platform or player.render_mode ~= defines.render_mode.game then return end
storage.player_surfaces = storage.player_surfaces or {}
if storage.player_surfaces[player.index] == surface.index then return end
storage.player_surfaces[player.index] = surface.index

View File

@ -1,8 +1,8 @@
{
"name": "Planet-PvP",
"version": "1.2.1",
"title": "Planet PvP",
"author": "SpRiTz708",
"name": "Planet-PvP-Green",
"version": "1.0.0",
"title": "Planet PvP Green",
"author": "Blizliam",
"factorio_version": "2.1",
"dependencies": [
"base >= 2.0.77",

View File

@ -52,14 +52,27 @@ local function scan_orbit(entity, planet_name)
end
end
-- Stored charge as a fraction of the buffer; drives how fast a radar accumulates scans.
local function scan_power(entity)
local buffer = entity.electric_buffer_size
if not buffer or buffer == 0 then return 1 end
return math.min(1, entity.energy / buffer)
end
function radar.on_orbital_scan_tick()
storage.radar_scan_progress = storage.radar_scan_progress or {}
for _, surface in pairs(game.surfaces) do
local platform = surface.platform
local location = platform and platform.space_location
if location and game.planets[location.name] then
for _, entity in pairs(surface.find_entities_filtered{type = "radar"}) do
if entity.valid and entity.active then
scan_orbit(entity, location.name)
local progress = (storage.radar_scan_progress[entity.unit_number] or 0) + scan_power(entity)
if progress >= 1 then
progress = progress - 1
scan_orbit(entity, location.name)
end
storage.radar_scan_progress[entity.unit_number] = progress
end
end
end

View File

@ -1,5 +1,6 @@
local base = require("base")
local drop_zone = require("drop_zone")
local observer = require("observer")
local setup = {}
local PLANETS = {"nauvis", "vulcanus", "fulgora", "gleba"}
@ -154,6 +155,15 @@ local function unlock(force, planet_name)
end
end
-- Surfaces are cheap until chunks get requested; create them all so orbital
-- radar can scout planets before any player has landed.
local function init_planet_surfaces()
for _, planet_name in ipairs(PLANETS) do
local planet = game.planets[planet_name]
if planet then planet.create_surface() end
end
end
local function show_admin(player)
if player.gui.screen.pvp_admin_frame then player.gui.screen.pvp_admin_frame.destroy() end
local frame = player.gui.screen.add{type = "frame", name = "pvp_admin_frame", caption = "ADMIN: CONFIGURE PLANET TEAMS", direction = "vertical"}
@ -193,9 +203,13 @@ function setup.on_init(observer)
for _, player in pairs(game.players) do player.set_shortcut_available("lock_drop_zone_shortcut", true) end
end
function setup.on_configuration_changed()
for _, key in pairs({"team_kit_spawned", "player_surfaces", "force_bases", "permadead", "pending_spectator", "force_colors", "base_label_ids", "player_targets", "grid_pos", "player_lights", "player_team_joined"}) do storage[key] = storage[key] or {} end
function setup.on_configuration_changed(event)
if event and event.mod_changes and event.mod_changes["Planet-PvP"] then
game.print("Save migrated from Planet-PvP to Planet PvP Green. All teams, bases and drop zones carry over.")
end
for _, key in pairs({"planet_teams", "team_kit_spawned", "player_surfaces", "force_bases", "permadead", "pending_spectator", "force_colors", "base_label_ids", "player_targets", "grid_pos", "player_lights", "player_team_joined", "observers", "radar_scan_progress"}) do storage[key] = storage[key] or {} end
get_hub_surface()
if storage.game_started then init_planet_surfaces() end
for planet_name, force_name in pairs(storage.planet_teams or {}) do
local force = game.forces[force_name]
if force then
@ -206,7 +220,11 @@ function setup.on_configuration_changed()
end
local fulgora = game.planets.fulgora
if fulgora and fulgora.surface then assign_fulgora_attractors(fulgora.surface) end
for _, player in pairs(game.players) do player.set_shortcut_available("lock_drop_zone_shortcut", true) end
for _, player in pairs(game.players) do
player.set_shortcut_available("lock_drop_zone_shortcut", true)
-- Restore observer UI for spectators whose button may not have survived a mod swap.
if player.controller_type == defines.controllers.spectator then observer.create_button(player) end
end
for _, player in pairs(game.connected_players) do
if not has_selected_team(player) then
teleport_to_hub(player)
@ -215,6 +233,13 @@ function setup.on_configuration_changed()
end
end
-- No writable "save loaded" event exists, so control.lua fires this via a
-- one-shot nth_tick(1). Covers saves hosted from before surfaces were
-- initialized at game start, where on_configuration_changed may not run.
function setup.on_save_loaded()
if storage.game_started then init_planet_surfaces() end
end
function setup.on_chunk_generated(event)
if event.surface and event.surface.name == "fulgora" then
assign_fulgora_attractors(event.surface, event.area)
@ -257,6 +282,7 @@ function setup.on_gui_click(event)
if not game.forces[name] then game.create_force(name) end
unlock(game.forces[name], planet); base.assign_force_color(name); storage.planet_teams[planet] = name
end
init_planet_surfaces()
local fulgora = game.planets.fulgora
if fulgora and fulgora.surface then assign_fulgora_attractors(fulgora.surface) end
storage.game_started = true; element.parent.destroy()