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

Automatically shovel rubble and crowbar crates #11554

Merged
merged 3 commits into from Mar 12, 2015

Conversation

Projects
None yet
4 participants
@Coolthulhu
Copy link
Contributor

commented Mar 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_with returns const pointers and so can't be used), but at the moment all crowbars are equally efficient. Invokes iuse::crowbar function rather than copypasting code.

Also fixed a minor bug where crowbaring a crate with high mechanics and strength could grant moves.

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.

Copy link
@BevapDin

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.

Copy link
@Coolthulhu

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.

@Zireael07

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2015

Great!

How about safes and stethoscopes?

{
// 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.

Copy link
@BevapDin

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.

Copy link
@Coolthulhu

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.

Copy link
@BevapDin

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.

Copy link
@Coolthulhu

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.


// 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);

This comment has been minimized.

Copy link
@BevapDin

BevapDin Mar 12, 2015

Contributor

xname isn't used anywhere?

@KA101 KA101 self-assigned this Mar 12, 2015

@KA101 KA101 merged commit 50c11c4 into CleverRaven:master Mar 12, 2015

1 check passed

default
Details

@Coolthulhu Coolthulhu deleted the cataclysmbnteam:autoshovel branch Apr 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.