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

[RDY] Initial craft entity implementation #28937

Merged
merged 7 commits into from Apr 9, 2019

Conversation

ifreund
Copy link
Contributor

@ifreund ifreund commented Mar 23, 2019

Summary

SUMMARY: Features "Represent in progress crafts as an item."

Purpose of change

First step in #29210
Closes #28775
Closes #25188
Fixes #28718
Fixes #28930
Closes #28698
Closes #28592
Fixes #26264
Closes #23971
Closes #21850
Fixes #18191

Describe the solution

  • Create a new item craft
  • Create a new funtion start_craft() to generate the item
  • Create a use action to work on the craft
  • Modify the craft activity to use the new item
  • Store the components in the craft item
  • Weight/volume of the craft item is the sum of the components
  • Reimplement long crafting
  • Fix/reimplement end of craft checks (waste materials/exp gain/rot)
  • Investigate the craft item inheriting the materials of its components
  • Fix item::type_name() (probably put "in progress craft" in the json and move the substitution string to the c++ code)
  • Improve craft item cosmetics (optional)
  • Search for bugs
  • Clean up code

Additional context

The main goal of this PR is to implement a fully functional craft item while keeping crafting mechanics mostly unchanged. It may prove easier to modify some checks to be incremental, but I really just want to get a solid foundation established that I can build on in subsequent pull requests.

@ifreund ifreund added Game: Mechanics Change Code that changes how major features work Crafting / Construction / Recipes Includes: Uncrafting / Disassembling [C++] Changes (can be) made in C++. Previously named `Code` Items / Item Actions / Item Qualities Items and how they work and interact <Bugfix> This is a fix for a bug (or closes open issue) Mechanics: Character / Player Character / Player mechanics labels Mar 23, 2019
@int-ua
Copy link
Contributor

int-ua commented Mar 23, 2019

Related suggestion to lessen spoilage of ingredients (especially for large batches): #28930

@ifreund
Copy link
Contributor Author

ifreund commented Mar 24, 2019

Like I said, I'm not aiming to change mechanics too much in this pr. General discussion of the crafting overhaul belongs in #29210

@ifreund ifreund marked this pull request as ready for review April 1, 2019 20:13
@ifreund
Copy link
Contributor Author

ifreund commented Apr 1, 2019

Whoops, wasn't quite ready to mark this as ready yet, still want to do a bit of code cleanup and it looks like I need to rebase as well.

@ifreund ifreund force-pushed the craft-entity branch 2 times, most recently from c5336f6 to e5d845f Compare April 1, 2019 21:52
@ifreund
Copy link
Contributor Author

ifreund commented Apr 1, 2019

Ok this is ready for review. I had initially planned to try and make in progress crafts look like their products, but that can wait for one of the many planned follow up prs addressing #28775

@ifreund ifreund mentioned this pull request Apr 1, 2019
20 tasks
@ifreund ifreund added this to Confirmed in 0.E Release via automation Apr 1, 2019
@ifreund ifreund added this to In progress in Tailoring Overhaul via automation Apr 1, 2019
@codemime
Copy link
Contributor

codemime commented Apr 1, 2019

I don't see spoilage being handled anywhere in you code. There's a possible exploit related to it:

  1. Start crafting food from perishable components.
  2. Get crafting interrupted to acquire an in-progress craft.
  3. Enjoy your imperishable investment.

My point is, a craft made of perishable items should also be perishable, and it shouldn't last longer than its first to go off ingredient.

@ifreund
Copy link
Contributor Author

ifreund commented Apr 1, 2019

Yeah, that's part of my todo list in #29210. I thought that the poor handling would be ok for now, but you're right that it is a little too exploitable to be merged in it's current state. Will look into a proper fix.

@ifreund
Copy link
Contributor Author

ifreund commented Apr 2, 2019

Ok, components now rot while in an in progress craft. The relative rot of the most rotten component at completion is transferred to the product. This may be a little unrealistic in some preservation recipes, but that's a subject for a different pr, this one is large enough.

src/activity_handlers.cpp Outdated Show resolved Hide resolved
src/activity_handlers.cpp Outdated Show resolved Hide resolved
src/activity_handlers.cpp Outdated Show resolved Hide resolved
src/crafting.cpp Outdated Show resolved Hide resolved
src/crafting.cpp Outdated Show resolved Hide resolved
src/item.cpp Outdated Show resolved Hide resolved
src/item.cpp Show resolved Hide resolved

for( const item &it : components ) {
if( it.has_flag( "HIDDEN_POISON" ) ) {
set_flag( "HIDDEN_POISON" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach isn't particularly robust: imagine adding new flags or removing them. Essentially this snipped is code duplication with all its drawbacks. I'd tweak item::has_flag instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I did it this way is that I wasn't sure if it made sense for all flags to be transferred and didn't want to cause any potential strange behavior. Will take another look at this.

src/item.cpp Outdated Show resolved Hide resolved
src/item.cpp Outdated Show resolved Hide resolved
src/item.cpp Outdated Show resolved Hide resolved
@ifreund
Copy link
Contributor Author

ifreund commented Apr 3, 2019

Ok, proposed solution for rot that actually better captures what the old code was trying to calculate and I think makes sense.

  • The craft entity essentially mimics the comestible stats of the product
  • On creation of the craft entity transfer the relative rot of the most rotten component to the craft entity
  • Upon completion transfer the rot from the craft entity to the product and byproducts
  • If the craft fails and components are returned, apply the delta relative rot of the craft item since creation

@ifreund ifreund changed the title Initial craft entity implementation [WIP] Initial craft entity implementation Apr 3, 2019
@kevingranade
Copy link
Member

kevingranade commented Apr 3, 2019

That makes sense to me, and has a number of great qualities.
Only deal with one item while in progress.
It's generous with rot times in case of success since finished products generally have slower rot than inputs.

Only weird edge case, what if an output is permafood?

@ifreund
Copy link
Contributor Author

ifreund commented Apr 3, 2019

Ok, I implemented basically what I outlined, for the permafood edge case I've decided to maintain the status quo of crafting permafood with old/rotting components being an exploit. Will look at fixing that in a future pr.

This is ready for review again and hopefully merge.
Edit: gonna do some more refactoring of the activity thanks to @codemime

@ifreund ifreund changed the title [WIP] Initial craft entity implementation Initial craft entity implementation Apr 3, 2019
@ifreund ifreund changed the title Initial craft entity implementation [WIP] Initial craft entity implementation Apr 3, 2019
@ifreund
Copy link
Contributor Author

ifreund commented Apr 3, 2019

Ok, now we should really be good to go.

@ifreund ifreund changed the title [WIP] Initial craft entity implementation Initial craft entity implementation Apr 3, 2019
@ifreund
Copy link
Contributor Author

ifreund commented Apr 4, 2019

Gotta love it when the tests catch all the stupid things I did. Should be good to go now.

}
if( !p->has_item( *craft ) ) {
p->add_msg_if_player( "%s no longer has the target '%s.' Aborting ACT_CRAFT.",
p->disp_name(), craft->tname() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can appear during normal play, so it shouldn't look like a debug message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure I intended for that to be a debug message but called the wrong function. I guess it could pop up rarely in normal play however and wouldn't cause any problems, so I'll take your advice and fix it.

Thanks for all your time reviewing this pr by the way!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks in return for your efforts working on it: the list of presumably resolved issues is quite impressive.

@ifreund ifreund changed the title Initial craft entity implementation [RDY] Initial craft entity implementation Apr 7, 2019
As well as:
-Apply suggestions from code review
-Fix crafting_interruption test
-Cleanup
Including:
-Activity cleanup from code review
-Make can_eat() return false for crafts
-Make get_comestible return type a const reference like it should have been
@kevingranade kevingranade merged commit 7225789 into CleverRaven:master Apr 9, 2019
0.E Release automation moved this from Confirmed to Done Apr 9, 2019
Tailoring Overhaul automation moved this from In progress to Done Apr 9, 2019
@kevingranade
Copy link
Member

This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there:

https://discourse.cataclysmdda.org/t/whats-happening-in-your-randomly-generated-apocalypse-part-2/14511/1488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Game: Mechanics Change Code that changes how major features work Items / Item Actions / Item Qualities Items and how they work and interact Mechanics: Character / Player Character / Player mechanics
Projects
0.E Release
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants