Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve resource, pipe and chest logic #16

Merged
merged 11 commits into from
Nov 21, 2021
Merged

Conversation

robot256
Copy link
Collaborator

@robot256 robot256 commented Nov 21, 2021

When checking a drill for remaining resources, check for resources matching any of that drill's compatible types.
Re-scan for depleted miners when fluid miner setting is newly enabled.
Improve debug prints for resource types.
* Calculate max_radius based on all prototypes in the game, rather than checking every single entity when it is built to see if it has a larger radius.
* Add filter to on_deconstruction_cancelled event.
* Calculate max_radius based on all prototypes in the game, rather than checking every single entity when it is built to see if it has a larger radius.
* Add filter to on_deconstruction_cancelled event.
Change pipe placement to utilize the direction-specific connection coordinates contained in the prototype data, rather than assuming symmetrical rotation.
* Removed unneeded validity checks for a fluidbox we know exists.
* Only build pipes if this miner has more than one connection.  (If a row depletes uniformly from the very end, no pipes are ever needed.)
* Fixed a logic error when checking if another miner is still using a chest.
* Simplified the search code to find entities targeting the chest.
* Fixed a crash if an inserter is nearby the chest but not targeting the chest.
* For burner miners, checks for inserters targeting the miner and deconstructs them too.
Note: Only case not covered is if an inserter is *taking* fuel from this miner in a daisy chain, in which case you might not want it to be deconstructed at all.
* Added logic so that pipes are only built to connections in use.  (This will fail if connected to a very rectangular entity or if there are more than one pipe connection on one side of the miner.)
* Added logic to not deconstruct a burner miner that is a source for an inserter moving fuel around.
@robot256
Copy link
Collaborator Author

Pretty sure this PR is complete. Can't think of anything else to add, unless you want to put the new inserter logic under a new setting. Appreciate if @nicolas-lang can test my changes.

@@ -123,9 +123,20 @@ local function debug_message_with_position(entity, msg)
end

function autodeconstruct.init_globals()
-- Find largest-range miner in the game
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be a risk that a drill that is larger gets added after initialization and so gets missed, perhaps that can be solved by updating the global when the game gets loaded

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will be caught in on_configuration_changed, when the prototype list is searched again. It fires whenever any mod is added, removed, or updated.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's fantastic

local _, err = pcall(autodeconstruct.on_cancelled_deconstruction, event)
if err then msg_all({"autodeconstruct-err-specific", "on_cancelled_deconstruction", err}) end
end,
{{filter="type", type="mining-drill"}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement

@softmix softmix merged commit 3a900ed into softmix:master Nov 21, 2021
@softmix
Copy link
Owner

softmix commented Nov 21, 2021

Thank you, much appreciated!

@@ -257,13 +246,23 @@ function autodeconstruct.build_pipes(drill)
pipeType = "se-space-pipe"
end
end

-- Connection position index is different from entity.direction
local conn_index = 1 -- north
Copy link
Collaborator

@nicolas-lang nicolas-lang Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defines.direction is an int type
since there seems to be no define for conn_direction I would simplify this using math to something like math.floor(drillData.direction/2)+1 and add a short comment reference to the direction defines prototype page

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I did that at first, wasn't sure I liked assuming that those constants never change and that it always is even. But I guess it is impossible to rotate any miner 45 degrees.

Copy link
Collaborator

@nicolas-lang nicolas-lang Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your current code would still break in a 45° rotation, similar to mine, it would just break slightly different, and in such a situation I usually prefer the solution with less code lines

Copy link
Collaborator Author

@robot256 robot256 Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mine would default to North. With divide by 2 in the index, it would crash on a fractional index unless round() is used to get to closest cardinal direction. Ah you already caught that.

Copy link
Collaborator

@nicolas-lang nicolas-lang Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree that's why I am suggesting math.floor which is similar to round. This way mine would assume the "nearest" rotation - This would probably still break "in-game" like your "default north" does. But we both agree since drills can not rotate 45° it is not an issue. --> Similar result: use the shorter code.

math.ceil , math.floor

  • Return the integer no greater than or no less than the given value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants