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

[WIP] Refactor firestarter handling #22703

Closed

Conversation

Projects
None yet
6 participants
@ZhilkinSerg
Copy link
Contributor

commented Jan 6, 2018

#21034 is stalled, so I'm reviving it.

What was changed:

  • added FIRESTARTER flag;
  • removed hard-coded ids from player::has_fire and player::use_fire;
  • fixes #22797;
  • fixes #21005;
  • fixes #22944.
@@ -8272,7 +8277,7 @@
"moves": 30
}
],
"flags": [ "FIRE", "LIGHT_240", "CHARGEDIM", "FLAMING", "DURABLE_MELEE", "TRADER_AVOID" ]
"flags": [ "FIRE", "LIGHT_240", "CHARGEDIM", "FLAMING", "DURABLE_MELEE", "TRADER_AVOID", "FIRESTARTER" ]

This comment has been minimized.

Copy link
@codemime

codemime Jan 6, 2018

Member

Both "FIRE" and "LIGHT_240" are presumably dead flags too.

This comment has been minimized.

Copy link
@ZhilkinSerg

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Jan 6, 2018

Author Contributor

FIRE flag is dead for items - I've removed it in #22699

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Jan 6, 2018

Author Contributor

On the other hand, FIRE flag is dead only in current master, but in this PR it defines item which is already burning, so it can be used to ignite something without spending any additional charges.

This comment has been minimized.

Copy link
@codemime

codemime Jan 7, 2018

Member

I'm not sure about LIGHT_X

You're right, it's still used (though a bit awkwardly). Please, disregard my comment concerning it.

in this PR it defines item which is already burning, so it can be used to ignite something without spending any additional charges.

Which means they're mutually exclusive and mustn't appear together in one item.

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Jan 23, 2018

Author Contributor

Which means they're mutually exclusive and mustn't appear together in one item.

Thanks, I've remove FIRESTARTER flag from those items which already have FIRE flag.

} else if( has_item_with_flag( "FIRESTARTER" ) ) {
auto firestarters = all_items_with_flag( "FIRESTARTER" );
for( auto &i : firestarters ) {
if( has_charges( i->typeId() , quantity ) ) {

This comment has been minimized.

Copy link
@codemime

codemime Jan 6, 2018

Member

The copy-pasted snippet can be eliminated by introducing a function which accepts quantity and returns a suitable firestarter (or the null item if none was found). Also, std::any() would be cleaner for this purpose.

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Jan 23, 2018

Author Contributor

There are two functions has_fire and use_fire which are only called directly by has_charges and use_charges functions.

image

Do you suggest combining these two functions to a single one bool player::use_or_has_fire( const int quantity, const bool ) to get rid of duplicate code and make existing functions just wrappers of a new one?

Edited: I don't know if it will be possible to combine these two functions as has_-functions are const and use_-functions are non-const.


What's with std::any()? I'm not familiar with it. Is it some construction which can return multiple types from same function?

This comment has been minimized.

Copy link
@codemime

codemime Jan 23, 2018

Member

Do you suggest combining these two functions to a single one bool

Not exactly, I had something like this in mind:

itype player::find_firestarter( int quantity ) const
{
    const auto firestarters = all_items_with_flag( "FIRESTARTER" );
    const auto it = std::find_if( firestarters.begin(), firestarters.end(), [quantity]( const item *elem ) {
	return elem->has_charges( quantity );
    } ); 
    return it == firestarters.end() ? ret_null : it->typeId();
}

    ...

    const itype firestarter = find_firestarter( quantity );
    if( firestarter != "null" ) {	// should become a proper id eventually.
        use_charges( firestarter, quantity );
    }
    ...

What's with std::any()? I'm not familiar with it. Is it some construction which can return multiple types from same function?

It returns iterators and generally useful as a replacement for for loops followed by conditions and return statements.

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Jan 23, 2018

Author Contributor

It returns iterators and generally useful as a replacement for for loops followed by conditions and return statements.

So, is it this - http://www.cplusplus.com/reference/algorithm/any_of/ ?

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Jan 23, 2018

Author Contributor

itype player::find_firestarter( int quantity ) const

I guess we should return item, not itype?

This comment has been minimized.

Copy link
@codemime

codemime Jan 26, 2018

Member

So, is it this

Yes, it is. I mistyped the name, so thanks.

I guess we should return item, not itype?

No, we probably shouldn't. The whole point of passing itype is that more than one instance of item can be used to acquire the needed amount of charges.

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Jan 26, 2018

Author Contributor

No, we probably shouldn't. The whole point of passing itype is that more than one instance of item can be used to acquire the needed amount of charges.

So item is certain instance of some item and itype will return item of some type (possibly even multiple items)?

@ZhilkinSerg ZhilkinSerg changed the title Refactor firestarter handling [WIP] Refactor firestarter handling Jan 12, 2018

ZhilkinSerg added some commits Jan 23, 2018

ZhilkinSerg added some commits Jan 23, 2018

@codemime

This comment has been minimized.

Copy link
Member

commented Jan 23, 2018

What about "bio_laser" and "bio_tools"? I don't see them being handled anymore (actually, I'm not sure if the later bionic even exists).

@Leland

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2018

Take a look at #21005 – will probably close it as well

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor Author

commented Jan 24, 2018

Take a look at #21005 – will probably close it as well

Yes, that would be fixed too.

ZhilkinSerg added some commits Jan 24, 2018

@Night-Pryanik

This comment has been minimized.

Copy link
Member

commented Feb 16, 2018

#22944 should be fixed too.

@kevingranade

This comment has been minimized.

Copy link
Member

commented Feb 16, 2018

You might be doing this already, if so cool.
This needs to respect the differences between firestarters, and the differences between firestarting jobs.
I.e. you have open flame (lighters, torch, nearby fire, flamethrower), sparks (flint and steel), and heat source (bow drill, magnifying lens) then you have lighting jobs, like fixed and time insensitive (campfire, kiln), dynamic and time critical (lighting fuses), and maybe fast but very easy (propane torch, oil soaked torch).

Some of these don't work together (flint and steel or bow drill can't reasonably light a dynamite fuse), some might be iffy (flint and steel and kiln).

return true;
} else if( has_item_with_flag( "FIRESTARTER" ) ) {

This comment has been minimized.

Copy link
@BevapDin

BevapDin Mar 6, 2018

Contributor

There is no need to check for suitable items first, just iterate over all suitable items directly:

    ...
    return true;
}
for( item *const i : all_items_with_flag(...) ) {
    if( ... ) {
        return true;
    }
}
return false;

If there are no suitable items, the loop will iterate over an empty vector, which means it will be skipped anyway.

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor Author

commented Apr 2, 2018

Temporary closing this.

@ZhilkinSerg ZhilkinSerg closed this Apr 2, 2018

@ZhilkinSerg ZhilkinSerg reopened this Aug 31, 2018

@ZhilkinSerg ZhilkinSerg force-pushed the ZhilkinSerg:jsonize-firestarters branch to 915936d Aug 31, 2018

@Night-Pryanik

This comment has been minimized.

Copy link
Member

commented Jan 8, 2019

@ZhilkinSerg is there any chance of reviving this?

@ZhilkinSerg

This comment has been minimized.

Copy link
Contributor Author

commented Jan 8, 2019

Most of the changes from current PR were already implemented in #25276. There is little to be done except for expanding as outlined in #22703 (comment).

@Night-Pryanik

This comment has been minimized.

Copy link
Member

commented Jan 8, 2019

Oh, my bad. I thought the thing wasn't merged at all.

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.