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

Fix mining using a pickaxe always causes an error #77906

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

osuphobia
Copy link
Contributor

@osuphobia osuphobia commented Nov 16, 2024

Summary

Bugfixes "Fix mining using a pickaxe always causes an error"

Purpose of change

Fix #77865

Describe the solution

Use a better way by andrei8l to check if the tool disappered during mining.

Testing

Loaded the save from #76783 , game did not crash when earthshaper's pickaxe expired during mining.
Using normal pickaxes and jackhammers also didn't cause an error.

Additional context

First check if the tool uses charge
@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Nov 16, 2024
@andrei8l
Copy link
Contributor

andrei8l commented Nov 16, 2024

I don't think this is correct. Items that use charges as fuel are NOT count_by_charges(). That being said, I am not aware of any mining tool that uses charges. magiclysm pickaxes (?)

@osuphobia osuphobia marked this pull request as draft November 16, 2024 09:54
@osuphobia
Copy link
Contributor Author

I don't think this is correct. Items that use charges as fuel are NOT count_by_charges(). That being said, I am not aware of any mining tool that uses charges. magiclysm pickaxes (?)

You are right, I remembered it wrong.
I'll check if craft_has_charges() works.

@andrei8l
Copy link
Contributor

Try this:

diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp
index 5ab4240c1e..1c7b07a894 100644
--- a/src/activity_handlers.cpp
+++ b/src/activity_handlers.cpp
@@ -1869,12 +1869,10 @@ void activity_handlers::pickaxe_finish( player_activity *act, Character *you )
                                 _( "<npcname> finishes digging." ) );
     here.destroy( pos, true );
     if( !act->targets.empty() ) {
-        item &it = *act->targets.front();
-        if( it.is_null() || it.charges <= 0 ) {
-            debugmsg( "pickaxe expired during mining" );
-            return;
+        item_location it = act->targets.front();
+        if( it ) {
+            you->consume_charges( *it, it->ammo_required() );
         }
-        you->consume_charges( it, it.ammo_required() );
     } else {
         debugmsg( "pickaxe activity targets empty" );
     }

I can't test it atm. The original fix was not good.

@osuphobia osuphobia marked this pull request as ready for review November 16, 2024 10:47
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Nov 16, 2024
@Night-Pryanik Night-Pryanik merged commit a76c4db into CleverRaven:master Nov 18, 2024
31 of 45 checks passed
@osuphobia osuphobia deleted the fix-pickaxe-mining branch November 18, 2024 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mining using a pickaxe always causes an error
3 participants