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 up[WIP] Refactor firestarter handling #22703
Conversation
ZhilkinSerg
added some commits
Jan 5, 2018
codemime
reviewed
Jan 6, 2018
| @@ -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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Jan 6, 2018
Author
Contributor
I'm not sure about LIGHT_X - see https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/item_factory.cpp#L165-L168.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
codemime
reviewed
Jan 6, 2018
| } 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.
This comment has been minimized.
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.
This comment has been minimized.
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.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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
changed the title
Refactor firestarter handling
[WIP] Refactor firestarter handling
Jan 12, 2018
ZhilkinSerg
added some commits
Jan 23, 2018
Leland
referenced this pull request
Jan 23, 2018
Closed
Lit refillable lighter can't be used to smoke tobacco pipe #22797
ZhilkinSerg
added some commits
Jan 23, 2018
This comment has been minimized.
This comment has been minimized.
|
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). |
This comment has been minimized.
This comment has been minimized.
|
Take a look at #21005 – will probably close it as well |
This comment has been minimized.
This comment has been minimized.
Yes, that would be fixed too. |
ZhilkinSerg
added some commits
Jan 24, 2018
Night-Pryanik
referenced this pull request
Feb 16, 2018
Closed
Flint and Steel cannot be used to Fire Kiln #22944
This comment has been minimized.
This comment has been minimized.
|
#22944 should be fixed too. |
This comment has been minimized.
This comment has been minimized.
|
You might be doing this already, if so cool. 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). |
helle253
referenced this pull request
Feb 19, 2018
Closed
Sawdust Generation during Woodworking/Furniture Construction #22993
BevapDin
reviewed
Mar 6, 2018
| return true; | ||
| } else if( has_item_with_flag( "FIRESTARTER" ) ) { |
This comment has been minimized.
This comment has been minimized.
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
added some commits
Mar 6, 2018
ZhilkinSerg
added
the
(S5 - OnHold / Stalled)
label
Apr 2, 2018
This comment has been minimized.
This comment has been minimized.
|
Temporary closing this. |
ZhilkinSerg
closed this
Apr 2, 2018
ZhilkinSerg
reopened this
Aug 31, 2018
ZhilkinSerg
force-pushed the
ZhilkinSerg:jsonize-firestarters
branch
to
915936d
Aug 31, 2018
ZhilkinSerg
closed this
Aug 31, 2018
This comment has been minimized.
This comment has been minimized.
|
@ZhilkinSerg is there any chance of reviving this? |
This comment has been minimized.
This comment has been minimized.
|
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). |
This comment has been minimized.
This comment has been minimized.
|
Oh, my bad. I thought the thing wasn't merged at all. |

ZhilkinSerg commentedJan 6, 2018
•
edited
#21034 is stalled, so I'm reviving it.
What was changed:
FIRESTARTERflag;player::has_fireandplayer::use_fire;