Page 1 of 4

[MOD 0.14] Filtered Deconstruction Planner 0.4.10

Posted: Thu Jan 28, 2016 3:09 am
by NearlyDutch
Type: Mod
Name: Filtered Deconstruction Planner
Description: Target specific objects to be deconstructed by bots or cut them from existing blueprints.
License: MIT
Version: v0.4.10
Release: 2016-11-06
Tested-With-Factorio-Version: 0.14.19
Category: Helper
Tags: filtered deconstruction
Download-Url: v0.4.10 at GitHub
Website: https://github.com/dkaisers/filtered-de ... on-planner
License
Long description
Picture
Version history

Re: [MOD 12.22] Filtered Deconstruction Planner 0.1.0

Posted: Thu Jan 28, 2016 7:17 am
by Supercheese
Niiice, I was just thinking an ability to filter like this would be great to have!

Re: [MOD 12.22] Filtered Deconstruction Planner 0.1.0

Posted: Thu Jan 28, 2016 1:51 pm
by NearlyDutch
Thanks, after I got some sleep I worked a bit more on the mod this morning and now you can choose between three different modes of deconstruction as explained in the updated long description and picture of the mod in the original post.

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.0

Posted: Thu Jan 28, 2016 4:24 pm
by Choumiko
That's a nice one :D

We should really request an item like a blueprint/deconstruction planner that does nothing but fire an event with player and entities in the selected area.

Of course i had to peek at the code, and found a potential issue for MP games, will add a comment in github shortly.

Edit: Forget the github comment, doing it here: in the on_marked_for_deconstruction event, you probably should check if exactly one player has the item on its cursor stack and that no other players have a deconstruction planner/module inserter/upgrade planner (if that mod still works) in the cursor stack. Because as far as i know you can't clearly distinguish which player triggered the event.

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.0

Posted: Thu Jan 28, 2016 8:11 pm
by NearlyDutch
I used the module inserter as basis and changed it to the current functionality, I guess that should be quite obvious when looking at the code :D

Concerning the multiplayer, how would that help me, to know if anybody else got a deconstruction planner in his stack? I can't really keep track of who is deconstructing what just to see if there is some overlap, or is there another way?

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.0

Posted: Thu Jan 28, 2016 8:16 pm
by Koub
You've one ultimate step you could do : search and replace planner, and you'll be praised as a god among men :)

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.0

Posted: Thu Jan 28, 2016 8:32 pm
by NearlyDutch
You mean like the upgrade planner mod that already exists on this forum? :D

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.0

Posted: Thu Jan 28, 2016 8:48 pm
by Koub
Doh

Image

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.0

Posted: Thu Jan 28, 2016 10:26 pm
by kds71
NearlyDutch wrote:Concerning the multiplayer, how would that help me, to know if anybody else got a deconstruction planner in his stack? I can't really keep track of who is deconstructing what just to see if there is some overlap, or is there another way?
This part of code in your mod rises a problem (three problems actually) in multiplayer

Code: Select all

		for _, p in pairs(game.players) do
			local stack = p.cursor_stack
			if stack.valid_for_read then
				if stack.name == "filtered-deconstruction-planner" then
					player = p
				else
					return
				end
			end
		end
1. If player 1 is holding an item other than filtered deconstruction planner in his hand, player 2 can't use filtered deconstruction planner at all.
2. If situation from point 1 occurs, filtered deconstruction planner used by player 2 will act like a normal deconstruction planner, which may lead to terrible results (like deconstructing half of the factory while player just wanted to remove some inserters): you can't just exit the function, you need to cancel deconstruction before returning.
3. If player 1 is holding a filtered deconstruction planner in his hand, player 2 will be using filtered deconstruction planner with configuration that was set by player 1.

I have the same problem in my upgrade planner mod, and all I do is discard deconstruction alltogether if more than one player holds planner tool in the hand. It has to be done, otherwise it may lead to situation when player uses a planner tool with wrong configuration.

The code is rather simple, this is how it looks like in my mod:

Code: Select all

    -- Determine which player used upgrade planner.
    -- If more than one player has upgrade planner in their hand or one
    -- player has a upgrade planner and other has deconstruction planner,
    -- we can't determine it, so we have to discard deconstruction order.

    for i = 1, #game.players do

        if game.players[i].cursor_stack.valid_for_read then
            if game.players[i].cursor_stack.name == "upgrade-planner" then
                if upgrade or deconstruction then
                    entity.cancel_deconstruction(entity.force)
                    return
                end
                player = game.players[i]
                upgrade = true
            elseif game.players[i].cursor_stack.name == "deconstruction-planner" then
                if upgrade then
                    entity.cancel_deconstruction(entity.force)
                    return
                end
                deconstruction = true
            end
        end

    end

    if not player then return end
Koub wrote:You've one ultimate step you could do : search and replace planner, and you'll be praised as a god among men :)
Oh :(

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.0

Posted: Fri Jan 29, 2016 1:13 am
by NearlyDutch
Ah okay, I see. I tried to come up with code that would work with all possible "planner-mods" like this one, upgrade planner and module inserter:

Code: Select all

for _, p in pairs(game.players) do
	local stack = p.cursor_stack
	if stack.valid_for_read then
		if stack.type == "deconstruction-item" then
			if stack.name == "filtered-deconstruction-planner" and not found_deconstruction_item then
				player = p
			elseif found_deconstruction_item then
				entity.cancel_deconstruction(entity.force)
				return
			end

			found_deconstruction_item = true
		end
	end
end

if not player then
	return
end
So, this should only allow the rest of the function to work, if there is exactly one item in a player's hand that is a filtered deconstruction planner. In any case the loop finds more than one item of type "deconstruction-item", which all those different planners are, it will cancel the deconstruction and return the function. If the loop finished without the player being set, there was no filtered deconstruction planner used and the function is also returned, as this case will be handled by another mod or the base game in case of the default deconstruction planner.
While this way should be safe to use with any combination of "planner-mods", the downside to this general approach is, that two default deconstruction planners can't be used simultaneously anymore, too... :/

Does this make sense? If so, I'll release the patch for the mod asap.

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.0

Posted: Fri Jan 29, 2016 2:18 am
by kds71
Yeah, it does make a sense - and now I will have to fix my mod, because it is assuming that there are no other deconstruction planners than the one that comes with the base game :)
NearlyDutch wrote:the downside to this general approach is, that two default deconstruction planners can't be used simultaneously anymore, too... :/
Unfortunatelly, nothing can be done about that unless the on_marked_for_deconstruction event would pass not only deconstruction entity, but also a player that caused deconstruction.

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.1

Posted: Fri Jan 29, 2016 1:02 pm
by NearlyDutch
Yeah, sorry about that :D

Just published the 0.2.1 release, link in original post of this thread. This should fix the possible multiplayer issue as described by Choumiko and kds71.

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.1

Posted: Sat Jan 30, 2016 6:13 am
by mbritb
NearlyDutch - Fix it, Fix it, Fix it!

Sooooo, I downloaded your mod! Soooo excited. So I was playing around with it and thought about giving it the ultimate test.

Removing concrete under structures. Yea, it won't remove concrete...period.

FISSSS IT!!! :D

On another note: I love this...I love you!!!! Best mod ever! haha!

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.1

Posted: Sat Jan 30, 2016 10:52 am
by mophydeen
It is not possible to target:
  • alien artifact
    wood (for trees)
    stone (for rocks) // using minable rock mod

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.1

Posted: Sun Jan 31, 2016 12:09 am
by mbritb
mophydeen wrote:It is not possible to target:
  • alien artifact
    wood (for trees)
    stone (for rocks) // using minable rock mod
You can use a deconstruction planner to pick up alien artifact and trees. But not stone. (in base game)

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.1

Posted: Sun Jan 31, 2016 1:36 am
by NearlyDutch
Wasn't very productive today due to a hangover, but I figured out how I will approach the raised issues. :D

I just realized, that items lying on the ground work differently than items placed/built. That's why you can't target alien artifacts in the way mophydeen probably means. Since there can be stone and wood also lying around and I want to keep the possibility open for items on the ground to be targeted, I won't make it so that wood and stone will be used to configure trees and rocks for targeting, but those will be able to be chosen with a selection tool that works like the eyedropper in your favorite graphics software to choose a color from an image.

Danielv123 posted the idea on reddit and after figuring out how to go about it, I think that would be the best solution. You'll click the eyedropper tool button, and while that tool is active, entities that you click on will be added to your filter configuration, as long as there is an empty slot available and the selected item is not already in there.

@brit, thanks for the kind words, but sadly I have to say that concrete below structures won't probably be possible. Since the filtered deconstruction planner is basically just a standard one with functionality and a GUI on top, it still prioritizes structures over flooring, when "drawing" that selection rectangle. And that is not game logic you can tinker with using mods, so at the moment I can't offer a solution for that problem, sorry. :/

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.1

Posted: Sun Jan 31, 2016 2:54 pm
by StanFear
NearlyDutch wrote:@brit, thanks for the kind words, but sadly I have to say that concrete below structures won't probably be possible. Since the filtered deconstruction planner is basically just a standard one with functionality and a GUI on top, it still prioritizes structures over flooring, when "drawing" that selection rectangle. And that is not game logic you can tinker with using mods, so at the moment I can't offer a solution for that problem, sorry. :/

for my subsurface mod, I am developping an alternative to the deconstruction planner for selecting areas, maybe, it could be used to manage removing only concrete (my custom event sends out the area selected and not the entities inside of it !) if you are interested, I can (once I finished it) release it as a small utility mod !

oh, and well done on this mod ! how many times have I wanted to remove only a type of items, and ended up removing items one by one ^^

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.2.1

Posted: Sun Jan 31, 2016 9:10 pm
by NearlyDutch
Sounds like exactly the solution needed, Stan. Looking forward to that release. Do you make heavy use of the on_tick event? Because those UPS are rare and sacred :D

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.3.0

Posted: Mon Feb 01, 2016 2:28 am
by NearlyDutch
Release v0.3.0 adds a different way to select items to filter: the eyedropper tool. (Which you need to target trees, those need to be configured using the eyedropper now)

Image

Changelog:
- Added eyedropper tool to select entities
- Removed configuration slot limit
- Removed need to save before filter is applied
- Fixed item-on-ground issues
- Changed GUI look and feel

Re: [MOD 0.12.22] Filtered Deconstruction Planner 0.3.0

Posted: Mon Feb 01, 2016 6:25 am
by Koub
Hi,

I haven't had the time to try your mod yet (having no time to play at all), but was wondering : have you considered using the "let go" shortcut key to "drop" your eyedropper tool ?