[MOD 0.16] Upgrade planner

Topics and discussion about specific mods
factoriofrenzy
Burner Inserter
Burner Inserter
Posts: 17
Joined: Thu Mar 24, 2016 4:44 pm
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by factoriofrenzy »

Thanks a bunch!!!
Attachments
Screen Shot 2016-08-28 at 18.59.47.png
Screen Shot 2016-08-28 at 18.59.47.png (471.4 KiB) Viewed 6610 times

Qon
Smart Inserter
Smart Inserter
Posts: 2119
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by Qon »

factoriofrenzy wrote:Here it is
Your blue --> purple belts merge is bottlenecked to the speed of 4 blue belts the by your express splitters. You should use purple splitters when merging the blue belts.

ShawnShepard
Burner Inserter
Burner Inserter
Posts: 12
Joined: Fri Jul 15, 2016 2:15 am
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by ShawnShepard »

Hello, Great mod, I use this so often and highly suggest to all players.

Can you please update it for 14.x latest?

Thank you and keep up the great work!

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by Klonan »

I have updated the mod for 0.14, and also added support removing and/or deconstructing trees

Arumba
Long Handed Inserter
Long Handed Inserter
Posts: 62
Joined: Sat Aug 29, 2015 6:46 pm
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by Arumba »

Small bug report; If you click on a single pixel (no box drag at all) in multiplayer the game instantly crashes.

jsmith45
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Sep 08, 2016 12:09 am
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by jsmith45 »

One feature I've been wanting with this mod is the ability to upgrade blueprints. Say I have a yellow belt balancer blueprint, but I've reached the point in the game where I never use yellow, and want blue-belt version. Or say I want to upgreade my normal rail blueprints to use an electric rail mod's rails. Placing the blueprint, upgrading it, and re-creating the blueprint is slow and obnoxious.

So I've coded up a modification of this mod that supports exactly that. With these changes simply clicking the upgrade planner GUI icon with a blueprint in hand will instantly upgrade the blueprint (and also the blueprint's icon), according to the current configuration. A minor caveat: Upgrades to a blurprint where the new object has a different size may not always work correctly. It does not crash, but some entites may not get placed since they would overlap. This can occur even when the upgraded entities don't appear to overlap. So just avoid upgrades to different sized entities when using blueprint upgrades.

The core code is:

Code: Select all

function upgrade_blueprint(player, blueprint)

    if not blueprint.is_blueprint_setup() then return end

    local config = global["config"][player.name]
    if config ~= nil then

        local bluedata=blueprint.get_blueprint_entities()
        for i=#bluedata,1,-1 do
            local belt=bluedata[i]

            local upgrade = get_upgrade_for_entity_name(config,belt.name)
            if upgrade ~= nil then
                if upgrade ~="deconstruction-planner" then
                    belt.name=item_name_to_entity_name(upgrade)
                else
                    table.remove(bluedata, i)
                end
            end
        end

        blueprint.set_blueprint_entities(bluedata)

        if(not blueprint.is_blueprint_setup()) then return end

        local icons=blueprint.blueprint_icons
        for i = 1,#icons do
            local icon=icons[i]
            local item_name = signal_to_item_name(icon.signal)
            local upgrade = get_upgrade_for_item_name(config,item_name)
            if upgrade then
                if upgrade ~="deconstruction-planner" then
                    icon.signal.name=upgrade
                else
                    icon.signal.name=nil
                end
            end
        end
        blueprint.blueprint_icons=icons
        if #blueprint.blueprint_icons == 0 then blueprint.blueprint_icons=blueprint.default_icons end
    end
end
That code gets plugged in to the gui_click event like so:

Code: Select all

if element.name == "upgrade-planner-config-button" then
    if(player.cursor_stack.valid_for_read and player.cursor_stack.type == "blueprint") then
        upgrade_blueprint(player,player.cursor_stack)
    else
        gui_open_frame(player)
    end
That code uses a few auxiliary functions not currently present in the mod.
They are defined below:

Code: Select all


function item_name_to_prototype(name) --or nil
    if name then
        return game.item_prototypes[name]
    end
end

function item_prototype_to_entity_prototype (item) --or nil
    if item and item.place_result then
        return item.place_result
    end
end

function item_name_to_entity_name(name)
    local entity = item_prototype_to_entity_prototype(item_name_to_prototype(name))
    if entity then 
        return entity.name 
    end   
end

function signal_to_item_name(signal)  --or nil
    if signal and signal.type == "item" then
       return signal.name
    end
end

function get_upgrade_for_item_name(config,name)
    local index = 0
    for i = 1, #config do
        if config[i].from == name then
            index = i
            break
        end
    end
    if index>0 then
        return config[index].to
    end
end

function get_upgrade_for_entity_name(config,name)
    if name then
        local index = 0
        for i = 1, #config do
            if item_name_to_entity_name(config[i].from) == name then
                index = i
                break
            end
        end
        if index>0 then
            return config[index].to
        end
    end
end
The helpers correctly handle entities whose names do not match their item's name. Having written, I decided to ugrade the rest of the mod to use these helpers, so that the whole mod works with entities whose names don't match their items name, and to fix 2 crashing bugs in version 1.2.5 of the mod. I'm attaching the final control.lua file that can be dropped into the mod. I may have introduced some new bugs, but everything seems to be working for me.

Klonan, I'd appreciate it if you would consider merging in these changes.
Attachments
control.lua
(32.53 KiB) Downloaded 132 times

doktorstick
Fast Inserter
Fast Inserter
Posts: 152
Joined: Fri Aug 12, 2016 10:22 pm
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by doktorstick »

Whenever you upgrade an entity using upgrade planner, the entity being replaced does not have its defines.events.on_preplayer_mined_item invoked and the upgraded entity does not have its defines.events.on_built_entity invoked.

This effectively breaks any mod that needs state tracking initialized on built/mined.

doktorstick
Fast Inserter
Fast Inserter
Posts: 152
Joined: Fri Aug 12, 2016 10:22 pm
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by doktorstick »

BTW, as expected, SHIFT-upgrading works with modded items since robots do the deconstruction/construction for reals.
Last edited by doktorstick on Mon Sep 12, 2016 5:20 pm, edited 1 time in total.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by Klonan »

doktorstick wrote:Whenever you upgrade an entity using upgrade planner, the entity being replaced does not have its defines.events.on_preplayer_mined_item invoked and the upgraded entity does not have its defines.events.on_built_entity invoked.

This effectively breaks any mod that needs state tracking initialized on built/mined.

Thanks for the report,

I will fix it for the next version of the mod

Urbs
Inserter
Inserter
Posts: 34
Joined: Sat Nov 01, 2014 1:10 pm
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by Urbs »

Just upgrade to 1.2.6.

Getting the following error while trying to upgrade belts by hand (not with bots)

Image

aarondeal
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sun Jul 31, 2016 2:08 am
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by aarondeal »

Urbs wrote:Just upgrade to 1.2.6.

Getting the following error while trying to upgrade belts by hand (not with bots)

Image

Im getting the same error.

WhatheWorld
Inserter
Inserter
Posts: 45
Joined: Tue Apr 19, 2016 4:32 am
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by WhatheWorld »

aarondeal wrote:
Urbs wrote:Just upgrade to 1.2.6.

Getting the following error while trying to upgrade belts by hand (not with bots)

Image

Im getting the same error.
got a similar crash

Error while running event on_player_selected_area (ID 49)
Error while running event on_built_entity (ID 6)
__Factorissimo__/control.lua:271: attempt to index local 'entity' (a nil value)
stack traceback:
__upgrade-planner__/control.lua:735: in function 'on_selected_area'
__upgrade-planner__/control.lua:592: in function <__upgrade-planner__/control.lua:591>
Author of Personal Teleporter

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [MOD 0.12.16] Upgrade planner - v1.1.9

Post by Klonan »

Urbs wrote:Just upgrade to 1.2.6.

Getting the following error while trying to upgrade belts by hand (not with bots)

Image
Thanks for the report,

Fixed in 1.2.7

Arumba
Long Handed Inserter
Long Handed Inserter
Posts: 62
Joined: Sat Aug 29, 2015 6:46 pm
Contact:

Re: [MOD 0.14] Upgrade planner - v1.2.7

Post by Arumba »

Bug report: 0.14.9 modded game with Bobs + Angels + vanilla+ stuffs.

Clicking on the GUI button in the top left corner of the map I get this error:

Code: Select all

Error while running event on_gui_click (ID 1)
__upgrade-planner__/control.lua:44: attempt to index field '?' (a nil value)
It was working in earlier versions, to my memory 0.14.7 or so. It still works as long as I don't click that button. I don't know what has changed.

Ratzap
Filter Inserter
Filter Inserter
Posts: 371
Joined: Sun Aug 16, 2015 11:15 pm
Contact:

Re: [MOD 0.14] Upgrade planner - v1.2.7

Post by Ratzap »

I went to use the planner in a Dytech game, settings were no problem but as soon as I click an area with the planner object in hand the server crashed:

Code: Select all

2944.003 Error MainLoop.cpp:759: Exception at tick 20508000: Error while running event on_player_selected_area (ID 49)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
	__upgrade-planner__/control.lua:619: in function 'on_selected_area'
	__upgrade-planner__/control.lua:600: in function <__upgrade-planner__/control.lua:599>
2944.003 Error ServerMultiplayerManager.cpp:95: MultiplayerManager failed: "Error while running event on_player_selected_area (ID 49)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
	__upgrade-planner__/control.lua:619: in function 'on_selected_area'
	__upgrade-planner__/control.lua:600: in function <__upgrade-planner__/control.lua:599>"
2944.003 Info ServerMultiplayerManager.cpp:636: mapTick(20508000) changing state from(InGame) to(Failed)

Ratzap
Filter Inserter
Filter Inserter
Posts: 371
Joined: Sun Aug 16, 2015 11:15 pm
Contact:

Re: [MOD 0.14] Upgrade planner - v1.2.7

Post by Ratzap »

I tried again just now with 1.2.11 and it crashed the server still.

Code: Select all

 222.386 Info ServerMultiplayerManager.cpp:720: mapTick(21057011) received stateChanged peerID(1) oldState(TryingToCatchUp) newState(WaitingForCommandToStartSendingTickClosures)
 222.386 Info GameActionHandler.cpp:2548: MapTick(21057011) processed PlayerJoinGame peerID(1) playerIndex(0) mode(connect)
 222.480 Info ServerMultiplayerManager.cpp:720: mapTick(21057017) received stateChanged peerID(1) oldState(WaitingForCommandToStartSendingTickClosures) newState(InGame)
 270.753 Error MainLoop.cpp:759: Exception at tick 21059912: Error while running event on_player_selected_area (ID 49)
__upgrade-planner__/control.lua:637: attempt to index local 'belt' (a nil value)
 270.754 Error ServerMultiplayerManager.cpp:95: MultiplayerManager failed: "Error while running event on_player_selected_area (ID 49)
__upgrade-planner__/control.lua:637: attempt to index local 'belt' (a nil value)"
 270.754 Info ServerMultiplayerManager.cpp:636: mapTick(21059912) changing state from(InGame) to(Failed)

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [MOD 0.14] Upgrade planner - v1.2.7

Post by Klonan »

Ratzap wrote:I tried again just now with 1.2.11 and it crashed the server still.

Code: Select all

 222.386 Info ServerMultiplayerManager.cpp:720: mapTick(21057011) received stateChanged peerID(1) oldState(TryingToCatchUp) newState(WaitingForCommandToStartSendingTickClosures)
 222.386 Info GameActionHandler.cpp:2548: MapTick(21057011) processed PlayerJoinGame peerID(1) playerIndex(0) mode(connect)
 222.480 Info ServerMultiplayerManager.cpp:720: mapTick(21057017) received stateChanged peerID(1) oldState(WaitingForCommandToStartSendingTickClosures) newState(InGame)
 270.753 Error MainLoop.cpp:759: Exception at tick 21059912: Error while running event on_player_selected_area (ID 49)
__upgrade-planner__/control.lua:637: attempt to index local 'belt' (a nil value)
 270.754 Error ServerMultiplayerManager.cpp:95: MultiplayerManager failed: "Error while running event on_player_selected_area (ID 49)
__upgrade-planner__/control.lua:637: attempt to index local 'belt' (a nil value)"
 270.754 Info ServerMultiplayerManager.cpp:636: mapTick(21059912) changing state from(InGame) to(Failed)
Okay it should be fixed in 1.2.12

Ratzap
Filter Inserter
Filter Inserter
Posts: 371
Joined: Sun Aug 16, 2015 11:15 pm
Contact:

Re: [MOD 0.14] Upgrade planner - v1.2.7

Post by Ratzap »

Thanks, that worked now.

keryja
Burner Inserter
Burner Inserter
Posts: 12
Joined: Mon May 23, 2016 11:43 am
Contact:

Re: [MOD 0.14] Upgrade planner - v1.2.7

Post by keryja »

There's still an error happening when you try to upgrade an underground belt with different ends:
2016-09-27_23-45-40.png
2016-09-27_23-45-40.png (217.97 KiB) Viewed 6304 times
2016-09-27_23-45-49.png
2016-09-27_23-45-49.png (66.71 KiB) Viewed 6304 times

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [MOD 0.14] Upgrade planner - v1.2.7

Post by Klonan »

keryja wrote:There's still an error happening when you try to upgrade an underground belt with different ends:
2016-09-27_23-45-40.png
2016-09-27_23-45-49.png
Ok should be fixed

Post Reply

Return to “Mods”