diff --git a/.vscode/launch.json b/.vscode/launch.json index 216cfe6..1add307 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -42,7 +42,7 @@ "flib": true, "cybersyn": true, }, - "disableExtraMods": true + //"disableExtraMods": true }, { "type": "factoriomod", diff --git a/cybersyn/changelog.txt b/cybersyn/changelog.txt index 6bc22e0..b973149 100644 --- a/cybersyn/changelog.txt +++ b/cybersyn/changelog.txt @@ -1,14 +1,16 @@ --------------------------------------------------------------------------------------------------- -Version: 1.1.2 -Date: 2022-12-8 +Version: 1.1.4 +Date: 2022-12-9 Changes: - - Fixed a crash on newly generated worlds + - Made the recipe and research requirements for cybernetic combinators cheaper so that access to them in various modpacks is more in line with my intentions --------------------------------------------------------------------------------------------------- -Version: 1.1.1 +Version: 1.1.3 Date: 2022-12-8 Changes: - Fixed a crash when removing a fuel loader - Fixed a gui bug + - Fixed a crash on newly generated worlds + - Fixed a crash with breaking combinators --------------------------------------------------------------------------------------------------- Version: 1.1.0 Date: 2022-12-8 diff --git a/cybersyn/info.json b/cybersyn/info.json index 7570e63..ff96549 100644 --- a/cybersyn/info.json +++ b/cybersyn/info.json @@ -1,6 +1,6 @@ { "name": "cybersyn", - "version": "1.1.2", + "version": "1.1.4", "title": "Project Cybersyn", "author": "Mami", "factorio_version": "1.1", diff --git a/cybersyn/locale/en/base.cfg b/cybersyn/locale/en/base.cfg index 7897d9a..5725f19 100644 --- a/cybersyn/locale/en/base.cfg +++ b/cybersyn/locale/en/base.cfg @@ -32,7 +32,7 @@ cybersyn-combinator-output=Cybernetic combinator output cybersyn-combinator=Has 4 different control modes. Primary control allows providing and requesting. Optional Control allows setting thresholds per-item and reading all in progress deliveries. Depot control allows parked trains to be added to the network. Wagon control allows for reading the desired contents of the adjacent wagon. [technology-name] -cybersyn-train-network=Cybernetic train network +cybersyn-train-network=Cybersyn train network [technology-description] cybersyn-train-network=Train stop controllers capable of coordinating the inputs and outputs of an entire economy. diff --git a/cybersyn/prototypes/tech.lua b/cybersyn/prototypes/tech.lua index b788b53..dffedec 100644 --- a/cybersyn/prototypes/tech.lua +++ b/cybersyn/prototypes/tech.lua @@ -1,8 +1,8 @@ --By Mami -combinator_recipe = flib.copy_prototype(data.raw["recipe"]["train-stop"], COMBINATOR_NAME) +combinator_recipe = flib.copy_prototype(data.raw["recipe"]["arithmetic-combinator"], COMBINATOR_NAME) combinator_recipe.ingredients = { - {"copper-cable", 5}, - {"advanced-circuit", 5}, + {"copper-cable", 20}, + {"electronic-circuit", 10}, } combinator_recipe.enabled = false if (mods["nullius"]) then @@ -19,38 +19,27 @@ if (mods["nullius"]) then } end -cybersyn_tech = { - type = "technology", - name = "cybersyn-train-network", - icon = "__cybersyn__/graphics/icons/tech.png", - icon_size = 256, - --icon_mipmaps = 4, - prerequisites = { - "automated-rail-transportation", - "circuit-network", - "advanced-electronics" - }, - effects = { - { - type = "unlock-recipe", - recipe = COMBINATOR_NAME - }, - }, - unit = { - ingredients = { - {"automation-science-pack", 1}, - {"logistic-science-pack", 1} - }, - count = 250, - time = 30 - }, - order = "c-g-c" + +cybersyn_tech = flib.copy_prototype(data.raw["technology"]["automated-rail-transportation"], "cybersyn-train-network") + +cybersyn_tech.icon = "__cybersyn__/graphics/icons/tech.png" +cybersyn_tech.icon_size = 256 +cybersyn_tech.prerequisites = { + "automated-rail-transportation", + "circuit-network", } +cybersyn_tech.effects = { + { + type = "unlock-recipe", + recipe = COMBINATOR_NAME + }, +} +cybersyn_tech.unit.count = 3*cybersyn_tech.unit.count +cybersyn_tech.order = "c-g-c" if (mods["nullius"]) then -- Enable technology cybersyn_tech.order = "nullius-" .. (cybersyn_tech.order or "") - -- Use the same costs and requirements as for LTN cybersyn_tech.unit = { count = 100, ingredients = { @@ -61,4 +50,4 @@ if (mods["nullius"]) then } cybersyn_tech.prerequisites = { "nullius-checkpoint-optimization", "nullius-traffic-control" } cybersyn_tech.ignore_tech_tech_cost_multiplier = true -end \ No newline at end of file +end diff --git a/cybersyn/scripts/gui.lua b/cybersyn/scripts/gui.lua index 65d8219..3b1e27c 100644 --- a/cybersyn/scripts/gui.lua +++ b/cybersyn/scripts/gui.lua @@ -29,6 +29,8 @@ STATUS_NAMES_DEFAULT = "entity-status.disabled" ---@param comb LuaEntity ---@param player LuaPlayer function gui_opened(comb, player) + combinator_update(global, comb) + local rootgui = player.gui.screen local selected_index, signal, check, switch_state = get_comb_gui_settings(comb) diff --git a/cybersyn/scripts/main.lua b/cybersyn/scripts/main.lua index 3e778a9..cbe980d 100644 --- a/cybersyn/scripts/main.lua +++ b/cybersyn/scripts/main.lua @@ -90,7 +90,7 @@ local function on_refueler_broken(map_data, refueler_id, refueler) map_data.to_refuelers[refueler.network_name] = nil end end - map_data.stations[refueler_id] = nil + map_data.refuelers[refueler_id] = nil interface_raise_refueler_removed(refueler_id, refueler) end @@ -333,7 +333,7 @@ function on_combinator_network_updated(map_data, comb, network_name) refueler.network_name = network_name if network_name then local network = map_data.to_refuelers[network_name] - if network == nil then + if not network then network = {} map_data.to_refuelers[network_name] = network end @@ -398,18 +398,33 @@ function combinator_update(map_data, comb) local old_params = map_data.to_comb_params[unit_number] local has_changed = false - if params.operation ~= old_params.operation then - if (old_params.operation == MODE_PRIMARY_IO) and (params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST) then + local stop = map_data.to_stop[comb.unit_number] + if stop then + id = stop.unit_number + station = map_data.stations[id] + if station then --make sure only MODE_PRIMARY_IO gets stored on map_data.to_comb_params - params.operation = MODE_PRIMARY_IO - else - --NOTE: This is rather dangerous, we may need to actually implement operation changing - on_combinator_broken(map_data, comb) - on_combinator_built(map_data, comb) - interface_raise_combinator_changed(comb, old_params) - return + if station.display_state >= 2 then + params.operation = MODE_PRIMARY_IO_ACTIVE + elseif station.display_state == 1 then + params.operation = MODE_PRIMARY_IO_FAILED_REQUEST + else + params.operation = MODE_PRIMARY_IO + end + control.parameters = params end end + + if params.operation == MODE_PRIMARY_IO_ACTIVE or params.operation == MODE_PRIMARY_IO_FAILED_REQUEST then + params.operation = MODE_PRIMARY_IO + end + if params.operation ~= old_params.operation then + --NOTE: This is rather dangerous, we may need to actually implement operation changing + on_combinator_broken(map_data, comb) + on_combinator_built(map_data, comb) + interface_raise_combinator_changed(comb, old_params) + return + end local new_signal = params.first_signal local old_signal = old_params.first_signal local new_network = new_signal and new_signal.name or nil @@ -420,24 +435,19 @@ function combinator_update(map_data, comb) end if params.second_constant ~= old_params.second_constant then has_changed = true - local stop = map_data.to_stop[comb.unit_number] - if stop then - local id = stop.unit_number - local station = map_data.stations[id] - if station then - local pre = station.allows_all_trains - set_station_from_comb_state(station) - if station.allows_all_trains ~= pre then - update_stop_if_auto(map_data, station, true) - end - else - local refueler = map_data.refuelers[id] - if refueler then - local pre = refueler.allows_all_trains - set_refueler_from_comb(mod_settings, refueler) - if refueler.allows_all_trains ~= pre then - update_stop_if_auto(map_data, refueler, false) - end + if station then + local pre = station.allows_all_trains + set_station_from_comb_state(station) + if station.allows_all_trains ~= pre then + update_stop_if_auto(map_data, station, true) + end + else + local refueler = map_data.refuelers[id] + if refueler then + local pre = refueler.allows_all_trains + set_refueler_from_comb(mod_settings, refueler) + if refueler.allows_all_trains ~= pre then + update_stop_if_auto(map_data, refueler, false) end end end diff --git a/cybersyn/scripts/migrations.lua b/cybersyn/scripts/migrations.lua index 1d09167..bb6e7a0 100644 --- a/cybersyn/scripts/migrations.lua +++ b/cybersyn/scripts/migrations.lua @@ -103,6 +103,17 @@ local migrations_table = { map_data.refuelers = map_data.refuelers or {} map_data.to_refuelers = map_data.to_refuelers or {} end, + ["1.1.3"] = function() + ---@type MapData + local map_data = global + map_data.tick_state = STATE_INIT + map_data.tick_data = {} + for k, v in pairs(map_data.refuelers) do + if not v.entity_comb.valid or not v.entity_stop.valid then + map_data.refuelers[k] = nil + end + end + end, } --STATUS_R_TO_D = 5 diff --git a/cybersyn/scripts/train-events.lua b/cybersyn/scripts/train-events.lua index 818e8d5..76ceb42 100644 --- a/cybersyn/scripts/train-events.lua +++ b/cybersyn/scripts/train-events.lua @@ -374,9 +374,7 @@ local function on_train_leaves_stop(map_data, mod_settings, train_id, train) interface_raise_train_status_changed(train_id, STATUS_F, train.status) elseif train.status == STATUS_D then --The train is leaving the depot without a manifest, the player likely intervened - local depot = map_data.depots[train.parked_at_depot_id--[[@as uint]]] remove_train(map_data, train_id, train) - send_lost_train_alert(train.entity, depot.entity_stop.backer_name) end end