From 4bcad35a72210ddb4d331a38e6543fadbc764465 Mon Sep 17 00:00:00 2001 From: Adrian Date: Sat, 17 Oct 2020 17:20:36 +0200 Subject: [PATCH] Refactoring, localization, overlay setting --- changelog.txt | 28 ++++++- info.json | 2 +- locale/de/informatron.cfg | 16 ++++ locale/de/nauvis-melange.cfg | 2 + locale/en/informatron.cfg | 6 +- locale/en/nauvis-melange.cfg | 4 +- prototypes/entity/machines.lua | 2 +- prototypes/item/capsule.lua | 2 +- scripts/control/aliens.lua | 91 ++++++++++++----------- scripts/control/forces.lua | 13 ++-- scripts/control/machines.lua | 44 +++++------ scripts/control/players.lua | 126 ++++++++++++++++---------------- scripts/informatron/control.lua | 4 +- settings.lua | 6 ++ 14 files changed, 198 insertions(+), 148 deletions(-) create mode 100644 locale/de/informatron.cfg diff --git a/changelog.txt b/changelog.txt index 7198669..bfc9409 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,9 +1,34 @@ +--------------------------------------------------------------------------------------------------- +Version: 0.9.2 +Date: 17.10.2020 + Features: + - Added german localization for Informatron intergration + - Added option to disable overlay + Changes: + - Changed some localizations + - Lowered volume of spice accelarted heartbeat/breathing + Optimizations: + - Checked for validity of entities and forces + Bugfixes: + - Fixed callback calling methods of other interfaces, that either no longer exist or name has changed + - Fixed crash when using mod without Kux Running + +--------------------------------------------------------------------------------------------------- +Version: 0.9.1 +Date: 16.10.2020 + Changes: + - Removed a debug print + Bugfixes: + - Fixed callback for spice influence + --------------------------------------------------------------------------------------------------- Version: 0.9.0 Date: 15.10.2020 - Changes: + Features: - Added interface for getting a certain players spice status + Changes: - Rewrote most of the player regarding code, you can still play in existing worlds, but the addiction system has been resetted + Optimizations: - Optimised codebase, should be more performant and accurate now Bugfixes: - Fixed crash due to an empty table when killed by alien @@ -45,6 +70,7 @@ Date: 12.10.2020 - Added effect to speed up manual crafting modifier when using spice Changes: - Reorganized the mods player table + Optimizations: - Split interface into smaller interfaces (specialization) Bugfixes: - Fixed crash when using spice in a new game diff --git a/info.json b/info.json index 2349646..2fb7036 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "nauvis-melange", - "version": "0.9.0", + "version": "0.9.2", "title": "Nauvis Melange", "author": "Zetabite", "factorio_version": "0.18", diff --git a/locale/de/informatron.cfg b/locale/de/informatron.cfg new file mode 100644 index 0000000..305a21f --- /dev/null +++ b/locale/de/informatron.cfg @@ -0,0 +1,16 @@ +[nauvis-melange] +menu_nauvis-melange=[img=fluid/spice-gas]Nauvis Melange +title_nauvis-melange=Nauvis Melange +text_welcome=Willkommen zur Nauvis Melange Mod. Um anzufangen [img=item/spice] __ITEM__spice__ zu produzieren, erforsche [img=technology/spice-processing] __ITEM__spice__ Produktion. + +text_spice-processing=Um [img=item/spice] __ITEM__spice__ zu bekommen, musst du zuerst ein __ENTITY__worm-hole__ finden. Dieses kannst du erzeugen in dem du einen Wurm tötest oder eine __ITEM__sandtrout__ platzierst. Sehr selten kannst du es auch einfach mit Glück finde.\nDanach musst du darauf einen [img=item/water-injector-proxy] __ENTITY__water-injector__ platzieren, um das Loch mit Wasser zu füllen. Sobald es voll ist, wird der __ENTITY__water-injector__ explodieren und hinterlässt die __ITEM__pre-spice-mass__. Diese kannst du dann einfach abbauen. +menu_spice-processing=[img=item/spice] __ITEM__spice__ Produktion +title_spice-processing=__ITEM__spice__ Produktion + +text_alien-breeding=Aliens zu züchten ist ziemlich einfach. Sobald du es erstmal erforscht hast, kannst du ein [img=item/alien-probe] __ITEM__alien-probe__ erstellen. Dieses benutzt du dann nahe in Gegenwart eines Aliens, um eine Probe ihres Bluts zu erhalten. Dieses Blut kannst du dann in der __ENTITY__alien-growth-chamber__ benutzen um Alien Larven zu züchten. +menu_alien-breeding=[img=item/alien-growth-chamber] Aliens züchten +title_alien-breeding=Aliens züchten + +text_spacing-guild=Um Navigatoren auszubilden, brauchst du ein [img=technology/spacing-guild] __ENTITY__spacing-guild__n Gebäude. Dieses wirch auch benötigt um Raketen in den Orbit zu bringen, das sie Kontrolle über die Raumfahrt haben. Die [img=item/spacing-guild] __ENTITY__spacing-guild__ braucht Massen an __ITEM__spice__ gas um richtig zu funktionieren, sei vorbereitet. +menu_spacing-guild=[img=technology/spacing-guild] Die __ENTITY__spacing-guild__ +title_spacing-guild=Die __ENTITY__spacing-guild__ \ No newline at end of file diff --git a/locale/de/nauvis-melange.cfg b/locale/de/nauvis-melange.cfg index a1e2061..f18def6 100644 --- a/locale/de/nauvis-melange.cfg +++ b/locale/de/nauvis-melange.cfg @@ -54,12 +54,14 @@ spice-evolution-factor=__ITEM__spice__ Evolutions-Faktor spice-direct-evolution-level=__ITEM__spice__ induzierte Stufe spice-evolve-neighbours=Erlaube Evolution des Nachbarn spice-evolve-neighbours-radius=Evolutions Radius +spice-overlay=Zeige __ITEM__spice__-Overlay [mod-setting-description] spice-evolution-factor=Immer wenn ein Alien ein Objekt zerstört, das __ITEM__spice__ im Inventar hat, wird der Evolutions-Faktor mit diesem Faktor multipliziert und als neuer Evolutions-Fackor gesetzt. Setze auf 1.0 um dies aus zu schalten. spice-direct-evolution-level=Anzahl an Evolutions Stufen die ein Alien aufsteigt wenn es etwas tötet oder zerstört das __ITEM__spice__ enthält. 0, wenn keins aufsteigen soll, 4 wenn alle Nachbarn auf max. aufsteigen sollen. spice-evolve-neighbours=Entscheidet ob Nachbarn des Aliens entwickelt werden, wenn es __ITEM__spice__ findet. spice-evolve-neighbours-radius=Radius in dem Aliens als Nachbarn gesehen werden. +spice-overlay=Zeigt das __ITEM__spice__-Overlay (Blau-Transparent) [nauvis-melange] guild-approval-message=Die __ENTITY__spacing-guild__ erlaubt den __ENTITY__rocket__n-Start. diff --git a/locale/en/informatron.cfg b/locale/en/informatron.cfg index 3a18ec5..0230be2 100644 --- a/locale/en/informatron.cfg +++ b/locale/en/informatron.cfg @@ -4,13 +4,13 @@ title_nauvis-melange=Nauvis Melange text_welcome=Welcome to the Nauvis Melange mod. To get started on producing [img=item/spice] __ITEM__spice__, research [img=technology/spice-processing] __ITEM__spice__ processing. text_spice-processing=To get hold of the [img=item/spice] __ITEM__spice__ you need to find a __ENTITY__worm-hole__, which you can create by killing a worm or placing a __ITEM__sandtrout__, or find one by sheer luck.\nAfter this you need to place a [img=item/water-injector-proxy] __ENTITY__water-injector__ on it and fill the hole with water. Once its full the __ENTITY__water-injector__ will explode, leaving the __ITEM__pre-spice-mass__ behind. This you can then simply mine. -menu_spice-processing=[img=item/spice] Spice processing -title_spice-processing=Spice processing +menu_spice-processing=[img=item/spice] __ITEM__spice__ processing +title_spice-processing=__ITEM__spice__ processing text_alien-breeding=Breeding aliens is rather easy. Once researched, you can craft an [img=item/alien-probe] __ITEM__alien-probe__, which you then use near an alien to get a sample of their blood. This blood is then used in the __ENTITY__alien-growth-chamber__ to grow an alien leech. menu_alien-breeding=[img=item/alien-growth-chamber] Alien breeding title_alien-breeding=Alien breeding -text_spacing-guild=To create navigators for diverse uses, you require a [img=technology/spacing-guild] __ENTITY__spacing-guild__ building. Additionaly it is needed to launch a rocket, as they control space travel. The [img=item/spacing-guild] __ENTITY__spacing-guild__ requires massive amounts of __ITEM__spice__ gas to function. +text_spacing-guild=To create navigators for diverse uses, you require a [img=technology/spacing-guild] __ENTITY__spacing-guild__ building. Additionaly it is needed to launch a rocket, as they control space travel. The [img=item/spacing-guild] __ENTITY__spacing-guild__ requires massive amounts of __ITEM__spice__ gas to function, be prepared. menu_spacing-guild=[img=technology/spacing-guild] Spacing guild title_spacing-guild=Spacing guild \ No newline at end of file diff --git a/locale/en/nauvis-melange.cfg b/locale/en/nauvis-melange.cfg index 5060865..0089302 100644 --- a/locale/en/nauvis-melange.cfg +++ b/locale/en/nauvis-melange.cfg @@ -17,7 +17,7 @@ water-injector=Fills __ENTITY__worm-hole__s with water, to grow __ITEM__pre-spic worm-hole=Place a __ENTITY__water-injector__ on it to fill it with water, to grow __ITEM__pre-spice-mass__ [fluid-name] -spice-gas=Spice gas +spice-gas=__ITEM__spice__ gas [item-name] alien-probe=Alien probe @@ -53,12 +53,14 @@ spice-evolution-factor=__ITEM__spice__ evolution factor spice-direct-evolution-level=__ITEM__spice__ induced level spice-evolve-neighbours=Allow neighbours evolution spice-evolve-neighbours-radius=Evolution radius +spice-overlay=Shows __ITEM__spice__-overlay [mod-setting-description] spice-evolution-factor=Whenever an alien destroys an object with melange, this factor will be multiplied with the current evolution factor and set to the new evolution factor. Set to 1.0 to disable this behavior. spice-direct-evolution-level=Amount of levels an alien is evolved to when directly hitting a __ITEM__spice__ source. 0 if no alien shall level up, 4 if even the neighbouring aliens shall be evolved to max. level. spice-evolve-neighbours=Determines if neighbouring aliens should be evolved if an alien finds __ITEM__spice__. spice-evolve-neighbours-radius=Radius in which aliens are considered neighbours +spice-overlay=Shows __ITEM__spice__-overlay (blue transparent) [nauvis-melange] guild-approval-message=The __ENTITY__spacing-guild__ allows the __ENTITY__rocket__ to be launched. diff --git a/prototypes/entity/machines.lua b/prototypes/entity/machines.lua index b4b0b53..ae2bc43 100644 --- a/prototypes/entity/machines.lua +++ b/prototypes/entity/machines.lua @@ -7,7 +7,7 @@ local blank = { height = 64, } -function spacing_guild_fluid_box(production_type, position) +spacing_guild_fluid_box = function(production_type, position) local base_level = {['input'] = -1, ['output'] = 1} return { filter = 'spice-gas', diff --git a/prototypes/item/capsule.lua b/prototypes/item/capsule.lua index 1532094..00c9525 100644 --- a/prototypes/item/capsule.lua +++ b/prototypes/item/capsule.lua @@ -38,7 +38,7 @@ data:extend({ sound = { { filename = '__base__/sound/heartbeat.ogg', - volume = 1.0 + volume = 0.75 } }, }, diff --git a/scripts/control/aliens.lua b/scripts/control/aliens.lua index 7088b03..e5fa478 100644 --- a/scripts/control/aliens.lua +++ b/scripts/control/aliens.lua @@ -1,11 +1,11 @@ -function created_entity(event) +created_entity = function(event) local entity = event.entity - if entity.name == 'alien-probe-proxy' then + if entity and entity.valid and entity.name == 'alien-probe-proxy' then local surface = entity.surface local position = entity.position local radius = 5 local alien = surface.find_entities_filtered({type = 'unit', position = position, radius = radius, force = 'enemy', limit = 1}) - if alien[1] then + if alien[1] and alien[1].valid then local aliens_table = global.aliens alien = alien[1] local sample = nil @@ -14,8 +14,8 @@ function created_entity(event) elseif aliens_table.reverse['worm-turret'][alien.name] then sample = { name = 'worm-sample', count = 1 } end - if (sample) then - if (event.source) then + if sample then + if event.source then local player = event.source local inventory = player.get_main_inventory() if inventory.can_insert(sample) then @@ -29,61 +29,61 @@ function created_entity(event) end end -function destroyed_entity(event) +destroyed_entity = function(event) local cause = event.cause local entity = event.entity - if (cause) then - if (entity) then - if entity.type == 'turret' and string.match(entity.name, 'worm') then - create_worm_hole(entity) - else - spice_effects(cause, entity) - end + if cause and cause.valid and entity and entity.valid then + if entity.type == 'turret' and string.match(entity.name, 'worm') then + create_worm_hole(entity) + else + spice_effects(cause, entity) end end end -function create_worm_hole(entity) +create_worm_hole = function(entity) local surface = entity.surface - local pos = entity.position - pos = surface.find_non_colliding_position('worm-hole', pos, 2, 0.5, true) - if (pos) then - surface.create_entity({ name = 'worm-hole', position = pos }) + local position = entity.position + position = surface.find_non_colliding_position('worm-hole', position, 2, 0.5, true) + if position then + surface.create_entity({ name = 'worm-hole', position = position }) end end -function spice_effects(cause, victim) +spice_effects = function(cause, victim) cause = is_spice_collector(cause, victim) - if cause then + if cause and cause.valid then -- in case we later want to scale effect based on this local spice_amount = has_spice_in_fluidbox(victim) or has_spice_in_inventory(victim) if spice_amount then - local spice_settings = { - ['spice-evolution-factor'] = settings.global['spice-evolution-factor'].value, - ['spice-direct-evolution-level'] = settings.global['spice-direct-evolution-level'].value, - ['spice-evolve-neighbours'] = settings.global['spice-evolve-neighbours'].value, - ['spice-evolve-neighbours-radius'] = settings.global['spice-evolve-neighbours-radius'].value - } local force = cause.force - force.evolution_factor = force.evolution_factor * spice_settings['spice-evolution-factor'] - cause = evolve_alien(cause, spice_settings['spice-direct-evolution-level']) - apply_spice_to_alien(cause) - if spice_settings['spice-evolve-neighbours'] then - local surface = cause.surface - local position = cause.position - local aliens = surface.find_entities_filtered({ name = global.aliens.names, position = position, radius = spice_settings['spice-evolve-neighbours-radius'], force = 'enemy'}) - for _, alien in pairs(aliens) do - if alien ~= cause then evolve_alien(alien, spice_settings['spice-direct-evolution-level'] - 1) end + if force.valid and force.name == 'enemy' then + local spice_settings = { + ['spice-evolution-factor'] = settings.global['spice-evolution-factor'].value, + ['spice-direct-evolution-level'] = settings.global['spice-direct-evolution-level'].value, + ['spice-evolve-neighbours'] = settings.global['spice-evolve-neighbours'].value, + ['spice-evolve-neighbours-radius'] = settings.global['spice-evolve-neighbours-radius'].value + } + force.evolution_factor = force.evolution_factor * spice_settings['spice-evolution-factor'] + cause = evolve_alien(cause, spice_settings['spice-direct-evolution-level']) + apply_spice_to_alien(cause) + if spice_settings['spice-evolve-neighbours'] then + local surface = cause.surface + local position = cause.position + local aliens = surface.find_entities_filtered({ name = global.aliens.names, position = position, radius = spice_settings['spice-evolve-neighbours-radius'], force = 'enemy'}) + for _, alien in pairs(aliens) do + if alien ~= cause then evolve_alien(alien, spice_settings['spice-direct-evolution-level'] - 1) end + end end end end end end -function has_spice_in_fluidbox(victim) +has_spice_in_fluidbox = function(victim) if victim.type ~= 'character' then - if (victim.fluidbox) then - local fluidbox = victim.fluidbox + local fluidbox = victim.fluidbox + if fluidbox and fluidbox.valid then for i = 1, #fluidbox, 1 do if fluidbox.get_locked_fluid(i) == 'spice-gas' then return fluidbox.get_capacity(i) @@ -94,7 +94,7 @@ function has_spice_in_fluidbox(victim) return false end -function has_spice_in_inventory(victim) +has_spice_in_inventory = function(victim) local inventory = nil if victim.type == 'car' then inventory = victim.get_inventory(defines.inventory.car_trunk) @@ -121,19 +121,18 @@ function has_spice_in_inventory(victim) return false end -function evolve_alien(alien, steps) +evolve_alien = function(alien, steps) local next_level = get_next_level(alien.name, steps) if next_level ~= alien.name then local surface = alien.surface local position = alien.position - local force = alien.force alien.destroy() - alien = surface.create_entity({ name = next_level, position = position, force = force}) + alien = surface.create_entity({ name = next_level, position = position, force = 'enemy'}) end return alien end -function get_next_level(name, steps) +get_next_level = function(name, steps) local aliens_table = global.aliens for type_name, entry in pairs(aliens_table.dict) do if aliens_table.reverse[type_name][name] then @@ -146,7 +145,7 @@ function get_next_level(name, steps) return name end -function apply_spice_to_alien(alien) +apply_spice_to_alien = function(alien) local surface = alien.surface local position = alien.position surface.create_entity({ name = 'spice-speed-sticker', target = alien, position = position }) @@ -155,7 +154,7 @@ function apply_spice_to_alien(alien) end -- only allows melee units to collect spice -function is_spice_collector(cause, victim) +is_spice_collector = function(cause, victim) local aliens_table = global.aliens if aliens_table.melee[cause.name] then return cause @@ -163,7 +162,7 @@ function is_spice_collector(cause, victim) local surface = victim.surface local position = victim.position local brutus = surface.find_entities_filtered({name = aliens_table.names, position = position, radius = 1, force = 'enemy', limit = 1}) - if (brutus) then return brutus end + if brutus and brutus.valid then return brutus end end return false end diff --git a/scripts/control/forces.lua b/scripts/control/forces.lua index 696a092..cf725b2 100644 --- a/scripts/control/forces.lua +++ b/scripts/control/forces.lua @@ -1,14 +1,13 @@ local config = require('scripts.config') local VICTORY_SPICE_AMOUNT = config.VICTORY_SPICE_AMOUNT -local VICTORY_CHECK_TICK = config.VICTORY_CHECK_TICK -function force_created(event) +force_created = function(event) local force_index = event.force.index global.forces[force_index] = config.default.forces end -function forces_merged(event) +forces_merged = function(event) local force_table = global.forces local source_index = event.source_index local force_index = event.destination.index @@ -18,11 +17,11 @@ function forces_merged(event) force_table[source_index] = nil end -function force_reset(event) +force_reset = function(event) global.forces[event.force.index] = config.default.forces end -function checkSpiceVictory() +checkSpiceVictory = function() for force_index, entry in pairs(global.forces) do if entry.spice_shipped >= VICTORY_SPICE_AMOUNT then if remote.interfaces['kr-intergalactic-transceiver'] and remote.interfaces['kr-intergalactic-transceiver']['set_no_victory'] then @@ -34,7 +33,7 @@ function checkSpiceVictory() end end -function rocket_launched(event) +rocket_launched = function(event) local force_table = global.forces local force_index = event.rocket.force.index local spice_count = event.rocket.get_inventory(defines.inventory.rocket).get_item_count('spice') @@ -53,7 +52,7 @@ lib.events = { } lib.on_nth_tick = { - [VICTORY_CHECK_TICK] = function() + [config.VICTORY_CHECK_TICK] = function() checkSpiceVictory() end } diff --git a/scripts/control/machines.lua b/scripts/control/machines.lua index 2c742dc..897db15 100644 --- a/scripts/control/machines.lua +++ b/scripts/control/machines.lua @@ -1,10 +1,8 @@ local config = require('scripts.config') -local WATER_INJECTOR_CHECK_TICK = config.WATER_INJECTOR_CHECK_TICK - -function built_entity(event) +built_entity = function(event) local entity = event.created_entity - if(entity) then + if entity and entity.valid then if entity.name == 'water-injector-proxy' then local surface = entity.surface local pos = entity.position @@ -21,31 +19,35 @@ end as they are disabled anyways before being launched. This might be exploitable, but everything else would only hurt honest players --]] -function enable_silos(entity) +enable_silos = function(entity) local force = entity.force - local surface = entity.surface - local spacing_guilds = surface.find_entities_filtered({name = 'spacing-guild', force = force}) - local silos = surface.find_entities_filtered({name = 'rocket-silo', force = force}) - for _, silo in pairs(silos) do - if #spacing_guilds >= #silos then silo.active = true end + if force.valid then + local surface = entity.surface + local spacing_guilds = surface.find_entities_filtered({name = 'spacing-guild', force = force}) + local silos = surface.find_entities_filtered({name = 'rocket-silo', force = force}) + for _, silo in pairs(silos) do + if #spacing_guilds >= #silos then silo.active = true end + end end end -function rocket_launch_ordered(event) +rocket_launch_ordered = function(event) local silo = event.rocket_silo local force = silo.force - local surface = silo.surface - local spacing_guilds = surface.find_entities_filtered({name = 'spacing-guild', force = force}) - local silos = surface.find_entities_filtered({name = 'rocket-silo', force = force}) - if #spacing_guilds >= #silos then - force.print({'nauvis-melange.guild-approval-message'}) - else - force.print({'nauvis-melange.guild-intervention-message'}) + if force.valid then + local surface = silo.surface + local spacing_guilds = surface.find_entities_filtered({name = 'spacing-guild', force = force}) + local silos = surface.find_entities_filtered({name = 'rocket-silo', force = force}) + if #spacing_guilds >= #silos then + force.print({'nauvis-melange.guild-approval-message'}) + else + force.print({'nauvis-melange.guild-intervention-message'}) + end + silo.active = (#spacing_guilds >= #silos) end - silo.active = (#spacing_guilds >= #silos) end -function check_water_injectors() +check_water_injectors = function() local surface = game.surfaces[1] local water_injectors = surface.find_entities_filtered({name = 'water-injector'}) for _, entity in pairs(water_injectors) do @@ -72,7 +74,7 @@ lib.events = { } lib.on_nth_tick = { - [WATER_INJECTOR_CHECK_TICK] = function() + [config.WATER_INJECTOR_CHECK_TICK] = function() check_water_injectors() end } diff --git a/scripts/control/players.lua b/scripts/control/players.lua index 13e13e5..7fa118d 100644 --- a/scripts/control/players.lua +++ b/scripts/control/players.lua @@ -1,10 +1,10 @@ local config = require('scripts.config') -local PLAYER_CHECK_TICK = config.PLAYER_CHECK_TICK -local RENDER_REFRESH_TICK = config.RENDER_REFRESH_TICK -local OVERLAY_TIMER = config.OVERLAY_TIMER -local SPICE_DURATION = config.SPICE_DURATION local effect_table = config.effect_table +local OVERLAY_TIMER = config.OVERLAY_TIMER +local kux_running_setting = settings.global['Kux-Running_Enable'] + +global.callbacks = {} remote.add_interface('nauvis_melange_player', { consume_spice = function(player_index, factor, consequence, pre_consumption) @@ -14,7 +14,6 @@ remote.add_interface('nauvis_melange_player', { global.players[event.playerIndex].zoom_factor = event.zoomFactor end, spice_influence_changed_add = function(interface_name, function_name) - global.callbacks = global.callbacks or {} global.callbacks.spice_influence_changed = global.callbacks.spice_influence_changed or {} local id = interface_name..'-'..function_name @@ -25,7 +24,6 @@ remote.add_interface('nauvis_melange_player', { global.callbacks.spice_influence_changed[id] = entry end, spice_influence_changed_remove = function(interface_name, function_name) - global.callbacks = global.callbacks or {} global.callbacks.spice_influence_changed = global.callbacks.spice_influence_changed or {} local id = interface_name..'-'..function_name global.callbacks.spice_influence_changed[id] = nil @@ -35,7 +33,7 @@ remote.add_interface('nauvis_melange_player', { end }) -function has_spice_influence(player_index) +has_spice_influence = function(player_index) local entry = global.players[player_index] if entry.radar.tick or entry.craft_mod.tick then return true @@ -50,28 +48,23 @@ function has_bad_trip(player_index) return false end -function spice_influence_changed_raise(player_index) - global.callbacks = global.callbacks or {} - global.callbacks.spice_effects_changed = global.callbacks.spice_effects_changed or {} - if has_spice_influence(player_index) then - game.get_player(player_index).print("Spice status: on") - else - game.get_player(player_index).print("Spice status: off") - end +spice_influence_changed_raise = function(player_index) + global.callbacks.spice_influence_changed = global.callbacks.spice_influence_changed or {} + local event = { player_index = player_index, on_spice = has_spice_influence(player_index) } - for _, entry in pairs(global.callbacks.spice_effects_changed) do + for _, entry in pairs(global.callbacks.spice_influence_changed) do if entry then remote.call(entry.interface_name, entry.function_name, event) end end end -function apply_spice_to_vehicle(player) - if (player.vehicle) then - local vehicle = player.vehicle +apply_spice_to_vehicle = function(player) + local vehicle = player.vehicle + if vehicle and vehicle.valid then if vehicle.type == 'car' and not global.spice_effects_blacklist['name'][vehicle.name] then if not has_spice_effects(vehicle) then local surface = vehicle.surface @@ -84,7 +77,7 @@ function apply_spice_to_vehicle(player) end end -function vehicle_interaction(event) +vehicle_interaction = function(event) local player = game.get_player(event.player_index) apply_spice_to_vehicle(player) end @@ -104,7 +97,7 @@ local manage = { end, disable = function(player_index) local radar = global.players[player_index].radar - if radar.reference then + if radar.reference and radar.reference.valid then radar.reference.destroy() end radar.reference = false @@ -130,7 +123,7 @@ local manage = { bad_trip = { enable = function(player_index) - if not settings.global['Kux-Running_Enable'].value then + if not (kux_running_setting and kux_running_setting.value) then local player = game.get_player(player_index) local speed_modifier = player.character_running_speed_modifier player.character_running_speed_modifier = speed_modifier * 0.8 @@ -138,7 +131,7 @@ local manage = { global.players[player_index].bad_trip.tick = game.tick end, disable = function(player_index) - if not settings.global['Kux-Running_Enable'].value then + if not (kux_running_setting and kux_running_setting.value) then local player = game.get_player(player_index) local speed_modifier = player.character_running_speed_modifier player.character_running_speed_modifier = speed_modifier * 0.5 @@ -148,12 +141,13 @@ local manage = { } } -function used_capsule(event) +used_capsule = function(event) local capsule = event.item if capsule.name == 'spice' then local player_index = event.player_index local player = game.get_player(player_index) - if (player.character) then + local character = player.character + if character and character.valid then consume_spice(player_index, 1.0, 'bad_trip', 1) end end @@ -166,7 +160,7 @@ end 'no_effect': nothings happens, but the items are consumed 'nil': proceeds without checking if enough items exist and removes items --]] -function consume_spice(player_index, factor, consequence, pre_consumed) +consume_spice = function(player_index, factor, consequence, pre_consumed) local player = game.get_player(player_index) local character = player.character local addiction_level = global.players[player_index].addiction_level @@ -207,7 +201,7 @@ function consume_spice(player_index, factor, consequence, pre_consumed) return true end -function apply_spice_to_player(player) +apply_spice_to_player = function(player) local players_table = global.players local character = player.character local surface = character.surface @@ -216,35 +210,36 @@ function apply_spice_to_player(player) local addiction_level = players_table[player_index].addiction_level players_table[player_index].addiction_level = addiction_level + 1 -- Create entities/effects - if not settings.global['Kux-Running_Enable'].value then + if not (kux_running_setting and kux_running_setting.value) then surface.create_entity({ name = 'spice-speed-sticker', target = character, position = position }) end surface.create_entity({ name = 'spice-regen-sticker', target = character, position = position }) -- Table changes - global.render_table.spice_overlay[player_index] = true + global.render_table.spice_overlay[player_index] = game.players[player_index].mod_settings['spice-overlay'].value manage.radar.enable(player_index) manage.craft_mod.enable(player_index) apply_spice_to_vehicle(player) spice_influence_changed_raise(player_index) end -function player_joined(event) +player_joined = function(event) local players_table = global.players local player_index = event.player_index players_table[player_index] = players_table[player_index] or config.default.players if has_spice_influence(player_index) then - global.render_table.spice_overlay[player_index] = true + global.render_table.spice_overlay[player_index] = game.players[player_index].mod_settings['spice-overlay'].value end end -function player_died(event) +player_died = function(event) local player_index = event.player_index try_to_remove_spice_effects(player_index, true) end -function remove_addiction() +remove_addiction = function() for _, player in pairs(game.connected_players) do - if player.character then + local character = player.character + if character and character.valid then local players_table = global.players local addiction_level = players_table[player.index].addiction_level if addiction_level > 0 and math.random(0, 100) > 90 then @@ -254,15 +249,16 @@ function remove_addiction() end end -function try_to_remove_spice_effects(player_index, ignore) +try_to_remove_spice_effects = function(player_index, ignore) local players_table = global.players or {} local player = game.get_player(player_index) - if player.character or ignore then + local character = player.character + if ignore or (character and character.valid) then local entry = players_table[player_index] for _, key in pairs(effect_table) do local value = entry[key] if value.tick then - if value.tick <= (game.tick - value.duration) or ignore then + if ignore or value.tick <= (game.tick - value.duration) then manage[key].disable(player_index) end end @@ -277,7 +273,7 @@ function try_to_remove_spice_effects(player_index, ignore) end end -function player_check() +player_check = function() for _, player in pairs(game.connected_players) do local player_index = player.index if has_spice_influence(player_index) or has_bad_trip(player_index) then @@ -286,16 +282,16 @@ function player_check() end end -function player_moved(event) +player_moved = function(event) local player_index = event.player_index local player = game.get_player(player_index) - if (player.character) then - local character = player.character + local character = player.character + if character and character.valid then if has_spice_influence(player_index) then local radar = global.players[player_index].radar local surface = character.surface local reference = surface.create_entity({name = 'spice-radar', position = character.position, force = character.force}) - if radar.reference then + if radar.reference and radar.reference.valid then radar.reference.destroy() end radar.reference = reference @@ -303,19 +299,19 @@ function player_moved(event) end end -function player_removed(event) +player_removed = function(event) local player_index = event.player_index global.players[player_index] = nil global.render_table.spice_overlay[player_index] = nil end -function player_left(event) +player_left = function(event) local player_index = event.player_index global.render_table.spice_overlay[player_index] = nil end -function has_spice_effects(entity) - if (entity.stickers) then +has_spice_effects = function(entity) + if entity.stickers then for _, sticker in pairs(entity.stickers) do if sticker.name == 'spice-applied-sticker' then return true @@ -325,24 +321,26 @@ function has_spice_effects(entity) return false end -function render_refresh() - for player_index, _ in pairs(global.render_table.spice_overlay) do - local player = game.get_player(player_index) - local zoom_factor = global.players[player_index].zoom_factor - rendering.draw_sprite({ - sprite = 'item.spice-overlay', - x_scale = 160 * zoom_factor, - y_scale = 90 * zoom_factor, - tint = {r = 0.04, g = 0.18, b = 0.66}, - target = player.character, - surface = player.surface, - time_to_live = OVERLAY_TIMER, - player = {player} - }) +render_refresh = function() + for player_index, enabled in pairs(global.render_table.spice_overlay) do + if enabled then + local player = game.get_player(player_index) + local zoom_factor = global.players[player_index].zoom_factor + rendering.draw_sprite({ + sprite = 'item.spice-overlay', + x_scale = 160 * zoom_factor, + y_scale = 90 * zoom_factor, + tint = {r = 0.04, g = 0.18, b = 0.66}, + target = player.character, + surface = player.surface, + time_to_live = OVERLAY_TIMER, + player = {player} + }) + end end end -function check_and_call_kux_zooming() +check_and_call_kux_zooming = function() if script.active_mods['Kux-Zooming'] then if remote.interfaces['Kux-Zooming'] and remote.interfaces['Kux-Zooming']['onZoomFactorChanged'] then remote.call('Kux-Zooming', 'onZoomFactorChanged_add', 'nauvis_melange_player', 'onZoomFactorChanged') @@ -378,13 +376,13 @@ lib.on_load = function () end lib.on_nth_tick = { - [SPICE_DURATION] = function() + [config.SPICE_DURATION] = function() remove_addiction() end, - [PLAYER_CHECK_TICK] = function() + [config.PLAYER_CHECK_TICK] = function() player_check() end, - [RENDER_REFRESH_TICK] = function() + [config.RENDER_REFRESH_TICK] = function() render_refresh() end } diff --git a/scripts/informatron/control.lua b/scripts/informatron/control.lua index c57b6a2..fac820a 100644 --- a/scripts/informatron/control.lua +++ b/scripts/informatron/control.lua @@ -7,7 +7,7 @@ remote.add_interface('nauvis-melange', { end }) -function nauvis_melange_menu(player_index) +nauvis_melange_menu = function(player_index) return { ['spice-processing'] = 1, ['alien-breeding'] = 1, @@ -15,7 +15,7 @@ function nauvis_melange_menu(player_index) } end -function nauvis_melange_page_content(page_name, player_index, element) +nauvis_melange_page_content = function(page_name, player_index, element) if page_name == 'nauvis-melange' then element.add{type='label', name='text_1', caption={'nauvis-melange.text_welcome'}} else diff --git a/settings.lua b/settings.lua index bd38d04..83fef4d 100644 --- a/settings.lua +++ b/settings.lua @@ -1,4 +1,10 @@ data:extend({ + { + type = 'bool-setting', + name = 'spice-overlay', + setting_type = 'runtime-per-user', + default_value = true + }, { type = 'double-setting', name = 'spice-evolution-factor',