Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upAutomatically shovel rubble and crowbar crates #11554
Conversation
BevapDin
reviewed
Mar 12, 2015
| if( ( m->veh_at( examx, examy ) != nullptr || | ||
| m->tr_at( examx, examy ) != tr_null || | ||
| g->critter_at( examx, examy ) != nullptr ) && | ||
| !query_yn(_("Clear up that %s?"), m->tername(examx, examy).c_str() ) ) { |
This comment has been minimized.
This comment has been minimized.
BevapDin
Mar 12, 2015
Contributor
Previously xname (which is furnname), now it's tername and the function actually removes the furniture.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 12, 2015
Author
Contributor
Changed furnname to xname here, but I don't know what you mean by
and the function actually removes the furniture.
This comment has been minimized.
This comment has been minimized.
|
Great! How about safes and stethoscopes? |
BevapDin
reviewed
Mar 12, 2015
| { | ||
| // Check for a crowbar in the inventory | ||
| const auto has_prying = []( const item it ) { | ||
| const auto fun = it.type->get_use( "CROWBAR" ); |
This comment has been minimized.
This comment has been minimized.
BevapDin
Mar 12, 2015
Contributor
One line: return ...->has_use(...)
Btw. there is nothing wrong with casting the const away from the item returned by Character::items_with, just use a const_cast. Doing this is only problematic if the object itself was defined as const like this:
const int a = 10;
int &b = const_cast<int&>(a);
b = 20; // undefined behavior
int t = 100;
const int &v = t;
int &x = const_cast<int&>(v);
x = 200; // fine, because x==v==t and t is not const
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 12, 2015
Author
Contributor
Though then I'd need to handle the cases where the item returns -1.
Or rewrite the function to get the item position in inventory and use that explicitly with player methods.
This comment has been minimized.
This comment has been minimized.
BevapDin
Mar 13, 2015
Contributor
Though then I'd need to handle the cases where the item returns -1.
??? What item should return -1? Do you mean invoking the iuse function returning -1? Your current code already ignores the return value of the isue function.
At most you might need another overload version of bool player::invoke_item( item* used, const std::string &method ), one with the point that is forwarded to the iuse function. You can just add that point parameter to the existing function and make a compatibility function that calls the new version with the point being player::pos() (kind of a default value for that parameter).
However if you don't care about charges and assume iuse::crowbar will never use charges and will never destroy the tool, you can invoke the item returned by items_with and forget the return value.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 13, 2015
Author
Contributor
Do you mean invoking the iuse function returning -1? Your current code already ignores the return value of the isue function.
Yes.
I marked the solution as a hack partly for this reason. Also to know what to change later on (probably should add explicit TODO).
When the number of functions that need to invoke item that does x raises, I'll write a function that does it. Currently it only happens here and in butchery function and in both cases return value can be more or less safely ignored.
BevapDin
reviewed
Mar 12, 2015
|
|
||
| // Ask if there's something possibly more interesting than this crate here | ||
| // Shouldn't happen (what kind of creature lives in a crate?), but better safe than getting complaints | ||
| std::string xname = m->furnname(examx, examy); |
Coolthulhu commentedMar 12, 2015
Removes the prompt for clearing rubble, unless there is something on the rubble tile (like with foraging, except items aren't checked).
Adds the same to crates. This one is a bit hacky, because it doesn't use the actual tool (
character::items_withreturns const pointers and so can't be used), but at the moment all crowbars are equally efficient. Invokesiuse::crowbarfunction rather than copypasting code.Also fixed a minor bug where crowbaring a crate with high mechanics and strength could grant moves.