diff --git a/prototypes/electronic/el_ki/el_ki_linker.lua b/prototypes/electronic/el_ki/el_ki_linker.lua index 6b475cd..d9e5b3d 100644 --- a/prototypes/electronic/el_ki/el_ki_linker.lua +++ b/prototypes/electronic/el_ki/el_ki_linker.lua @@ -52,5 +52,13 @@ data:extend({ alt_selection_mode = {"any-entity"}, entity_filters = {"el_ki_beacon_entity","fi_ki_beacon_entity","fu_ki_beacon_entity"}, alt_entity_filters = {"el_ki_beacon_entity","fi_ki_beacon_entity","fu_ki_beacon_entity"} - } + }, + { + type = "sprite", + name = "el_ki_not_operable_icon", + filename = "__248k__/ressources/electronic/el_ki/el_ki_linker/el_ki_not_operable_icon.png", + width = 64, + height = 64, + scale = 1 + } }) \ No newline at end of file diff --git a/ressources/electronic/el_ki/el_ki_linker/el_ki_not_operable_icon.png b/ressources/electronic/el_ki/el_ki_linker/el_ki_not_operable_icon.png new file mode 100644 index 0000000..c7be20c Binary files /dev/null and b/ressources/electronic/el_ki/el_ki_linker/el_ki_not_operable_icon.png differ diff --git a/scripts/electronic/el_ki_script.lua b/scripts/electronic/el_ki_script.lua index d03154b..2dca596 100644 --- a/scripts/electronic/el_ki_script.lua +++ b/scripts/electronic/el_ki_script.lua @@ -232,7 +232,12 @@ end function destroy_ki_beacon(entity) clear_ki_beacon(entity) unregister_ki_beacon(entity) - count_supported_beacons() + count_total_beacons() + + if is_beacon_supported() then + global.ki.dirty = true + end + gui.update_main() end @@ -302,7 +307,7 @@ function register_ki_beacon(entity) global.ki.beacon[unit].entity = entity global.ki.beacon[unit].channel = global.ki.standardchannel - add_to_supported(unit) + add_to_channel(unit) global.ki.beacon[unit].supported = is_beacon_supported() entity.operable = false @@ -569,6 +574,21 @@ end function el_ki_beacon_update() el_ki_buffer1_adder() + + --if now less beacons then support max + if is_beacon_supported() then + local dif = global.ki.supported - count_total_beacons() + + local unsupported = get_unsupported_beacons() + for i,v in ipairs(unsupported) do + global.ki.beacon[v].supported = true + dif = dif - 1 + if dif == 0 then + break + end + end + end + for i,v in pairs(global.ki.beacon) do el_ki_single_beacon_update(i) end @@ -583,6 +603,11 @@ function el_ki_single_beacon_update(id) beacon_inv.clear() + if global.ki.beacon[id].icon then + rendering.destroy(global.ki.beacon[id].icon) + global.ki.beacon[id].icon = nil + end + if global.ki.channel[channel].core then local coreunit = global.ki.channel[channel].core if global.ki.core[coreunit] then @@ -597,12 +622,30 @@ function el_ki_single_beacon_update(id) end end end + + if not global.ki.beacon[id].supported then + if not global.ki.beacon[id].icon then + if global.ki.beacon[id].entity.valid then + global.ki.beacon[id].icon = make_not_operable_icon(global.ki.beacon[id].entity) + end + end + end end --================================================================================= --util --================================================================================= +function get_unsupported_beacons() + local unsupported = {} + for i,v in pairs(global.ki.beacon) do + if not v.supported then + table.insert(unsupported,i) + end + end + return unsupported +end + function make_beacon_text(entity) entity.surface.create_entity({name="flying-text", position=entity.position, text="CH: "..global.ki.beacon[entity.unit_number].channel, color={r=1, g=1, b=1}}) end @@ -615,7 +658,10 @@ function remove_request_ghost(entity) end end - +function make_not_operable_icon(entity) + local sprite = rendering.draw_sprite({sprite="el_ki_not_operable_icon", target=entity, x_scale=0.5, y_scale=0.5, surface=entity.surface, render_layer=200}) + return sprite +end function el_ki_buffer1_adder() for i,v in pairs(global.ki.channel) do @@ -690,7 +736,7 @@ function make_channel(unit) end end -function count_supported_beacons() +function count_total_beacons() local count = 0 for i,v in pairs(global.ki.channel) do --if not (i == 0) then @@ -704,13 +750,13 @@ function count_supported_beacons() end function is_beacon_supported() - if global.ki.supported >= count_supported_beacons() then + if global.ki.supported >= count_total_beacons() then return true end return false end -function add_to_supported(id) +function add_to_channel(id) local channel = global.ki.beacon[id].channel table.insert(global.ki.channel[channel].beacons, id) end @@ -750,7 +796,8 @@ function el_ki_supported_adder() if game.forces[1] then if game.forces[1].technologies['el_ki_sup_4_tech'].researched then global.ki.supported4 = true - global.ki.supported = 65535 + --global.ki.supported = 65535 + global.ki.supported = 10 gui.update_main() end end