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] Tailoring without thread charges #20569
Conversation
Coolthulhu
reviewed
Mar 16, 2017
| "name": "thread", | ||
| "description": "A small quantity of thread that could be used when sewing.", | ||
| "weight": 1, | ||
| "volume": "1ml", |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 16, 2017
Contributor
Pretty sure volume is for a full stack.
Volume for 1 thread was 5ml.
Don't specify stack_size and volume like that: stack size is a divisor on volume.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
Author
Contributor
When I set volume to 1000 ml, stackable to true and stack_size to 200 it gives thread enormous volume in-game (like 8 liters for 8 sinews), so volume should be defined per single item.
Coolthulhu
reviewed
Mar 16, 2017
| { "wooled", "furred", "leather_padded", "kevlar_padded" } | ||
| }; | ||
|
|
||
| // Materials those mods use | ||
| std::array<std::string, 4> mod_materials{ | ||
| const std::array<const std::string, 4> mod_materials{ |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 16, 2017
Contributor
Tabs here: you should replace all tabs with 4 spaces each.
If you're adding const everywhere, also add static so that they aren't regenerated every time the function is executed.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
Author
Contributor
Replaced all tabs with 4 spaces and made const arrays also static.
Coolthulhu
reviewed
Mar 16, 2017
| { "felt_patch", "fur", "leather", "kevlar_plate" } | ||
| }; | ||
|
|
||
| // TODO: Read data from \data\json\items\generic\filament.json |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 16, 2017
Contributor
Nowadays we use @todo for TODOs because the documentation system detects them.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
reviewed
Mar 16, 2017
| "flags": [ "NO_SALVAGE" ] | ||
| }, | ||
| { | ||
| "id": "sinew", |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 16, 2017
Contributor
Those 3 filaments below differ from each other by name, description, material and color.
You should define a base filament and have all of them copy-from it instead of redefining everything anew. Check out how it's done for car batteries.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
reviewed
Mar 16, 2017
| } | ||
| else | ||
| { | ||
| filament_quantity = crafting_inv.amount_of(filament); |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 16, 2017
Contributor
This won't happen in unmodded game and since you're hardcoding the IDs, you don't really care much about anything but hardcoded.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
Author
Contributor
That was actually a debug code block which I wrote first to check available quantities (with
p->add_msg_if_player(m_info, _("DEBUG: Caching filament=%s, quantity=%d, quantity_total=%d"), filament, filament_quantity, filament_have_total);).
I will remove this block it as it is not really used.
Coolthulhu
reviewed
Mar 17, 2017
| // Filament that can be used | ||
| const std::array<const std::string, 4> mod_filament{ | ||
| { "thread", "sinew", "plant_fibre", "yarn" } | ||
| }; |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
A better way than hardcode would be to create a requirement for filament and check that. That way it would not be hardcoded and you would not need to manually replicate what crafting process already does.
You access requirement by requirement_id( "id_here" ).obj(), and use it like:
const auto &req = making->requirements();
bool can_craft = req.can_make_with_inventory( crafting_inv, batch_size );
Then consume the resources:
for( const auto &it : req.get_components() ) {
consume_items( it, batch_size );
}
for( const auto &it : req.get_tools() ) {
consume_tools( it, batch_size );
}
Doing it this way would automatically ask for resources, so you may skip the second part and just consume manually. Still, the first part is great for asking if resources exist.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
Author
Contributor
I've already added filament requirement earlier when I changed recipes in #20270. I will try to implement its usage in sew_advanced just like you described. Thanks!
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
Author
Contributor
I've ran into issue - requirements come from the recipe. We are repairing or modifying item, so there's no recipe for that and I simply cannot call:
const auto &req = making->requirements();
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
const auto &req = requirement_id( "id_here" ).obj()
bool can_craft = req.can_make_with_inventory( crafting_inv, batch_size );
This comment has been minimized.
This comment has been minimized.
Coolthulhu
reviewed
Mar 17, 2017
| else if (filament_have < filament_left) | ||
| { | ||
| filament_used = filament_have; | ||
| }; |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
All this block looks equivalent to filament_used = std::min( filament_have, filament_left ).
This comment has been minimized.
This comment has been minimized.
Coolthulhu
reviewed
Mar 17, 2017
| { | ||
| break; | ||
| }; | ||
| }; |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
Repeating a whole block like that is not acceptable.
Just do not return at the end of the block and instead have the consumption happen after all the if/else here.
This comment has been minimized.
This comment has been minimized.
|
Also coding style:
One newline for |
This comment has been minimized.
This comment has been minimized.
|
Coding style updated. |
This comment has been minimized.
This comment has been minimized.
|
Looks like you didn't push the commits - I can't see the changes. |
This comment has been minimized.
This comment has been minimized.
|
I'm still struggling with switching to usage of requirements. It seems for me that it is impossible to mix different |
This comment has been minimized.
This comment has been minimized.
This is not worth working around. All crafting works like this. |
This comment has been minimized.
This comment has been minimized.
|
You changed all the |
Coolthulhu
reviewed
Mar 17, 2017
| for( const auto &it : req.get_tools() ) { | ||
| p->consume_tools( it, batch_size ); | ||
| } | ||
| p->consume_items(comps); |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
You consume the filament twice. You don't need batch_size when using the default value (1).
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
Author
Contributor
Hmm... I tested it in-game and it works fine - when I need to consume 16 filament to pad item with leather - 16 threads are consumed.
I will test it again.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
This could mean you aren't actually using the comps here.
Note that you are calling consume_items twice.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
Author
Contributor
I believe consume_items is used twice for various reasons: first for filament from the requirement and second for modding material (leather, kevlar, etc) - isn't it ?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
Still, it would be cleaner to sum up those requirements. You can add them just like numbers.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
•
Author
Contributor
It is possible to create and use padding requirements for leather, kevlar, but there are cases when materials aren't spent, but filament is spent and also cases where double amount of filament is used.
You damage your %s trying to modify it and also waste filament (%d)!
You fail to modify the clothing, and you waste filament (%d) and materials.
You modify your %s, but waste a lot of filament (%d).
You modify your %s using a total of %d filament!
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
I thought they're already a requirement. Nevermind then, can stay as is.
Coolthulhu
reviewed
Mar 17, 2017
| for( const auto &it : req.get_tools() ) { | ||
| p->consume_tools( it, batch_size ); | ||
| } | ||
| p->consume_items(comps); |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
You still have multiple copies of the consumption code. Keep it in one place.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
reviewed
Mar 17, 2017
| mod->item_tags.insert( the_mod ); | ||
| p->consume_items( comps ); | ||
| return thread_needed / 2; | ||
| p->add_msg_if_player(m_good, _("You modify your %s using a total of %d filament!"), mod->tname().c_str(), batch_size); |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
The word "filament" feels really weird here, even if technically correct.
Any native English speakers to confirm/deny?
Coolthulhu
reviewed
Mar 17, 2017
| } | ||
|
|
||
| const int filament_needed = mod->volume() / 125_ml + 10; // We need extra filament to lose it on bad rolls | ||
| int batch_size = filament_needed; |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
Instead of using batch_size, you can multiply a requirement:
const auto req = requirement_id("filament").obj() * filament_needed;
It would be safer than using batch_size, because someday batch rules may change to allow lower costs or similar effects.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
reviewed
Mar 17, 2017
| { "wooled", "furred", "leather_padded", "kevlar_padded" } | ||
| }; | ||
|
|
||
| // Materials those mods use | ||
| std::array<std::string, 4> mod_materials{ | ||
| const std::array<const std::string, 4> mod_materials{ |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
If the array itself is const, the type in it doesn't need to be, because constness of array will be passed down to its types when its used (unless you have pointers in the array, but you don't have them here). You can also make the arrays static.
static const std::array<std::string 4> array_name_here {
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
const int filament_required = mod->volume() / 125_ml + 10; // We need extra filament to lose it on bad rolls
const auto req = requirement_id("filament").obj() * filament_required;
const bool has_enough_filament = req.can_make_with_inventory(crafting_inv);+10 is not enough for bad rolls (which use x2 materials) in case item volume is bigger than 1250_ml, so player will get debug message How should we avoid this? Increasing +10 modifier to some bigger value is not a good solution in my opinion. |
This comment has been minimized.
This comment has been minimized.
Drop the "you manage to modify but waste extra thread" case and just make it fail in those cases. |
Coolthulhu
reviewed
Mar 17, 2017
| p->consume_tools(it, consumption_modifier); | ||
| } | ||
| } | ||
| if( consume_mats == true ) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
reviewed
Mar 17, 2017
| */ | ||
|
|
||
| bool consume_mats = true; | ||
| bool consume_reqs = true; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 17, 2017
Author
Contributor
consume_reqs is set to true only in one case - when you damage item.
p->add_msg_if_player(m_bad, _("You damage your %s trying to modify it and also waste %d filament charges!"),
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
consume_reqs looks true everywhere.
consume_mats has one case where it is false. Still, in all the other cases you overwrite the true with another true, which is 3 extra lines that do nothing.
This comment has been minimized.
This comment has been minimized.
Coolthulhu
reviewed
Mar 17, 2017
| consumption_modifier = 2; | ||
| filament_consumed = filament_required * consumption_modifier; | ||
| mod->item_tags.insert(the_mod); | ||
| p->add_msg_if_player(m_mixed, _("You modify your %s, but waste a lot of filament (%d charges)."), mod->tname().c_str(), filament_consumed); |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 17, 2017
Contributor
In every section, you recalculate the number just to print what you used. Would be cleaner if you had it once in consumption section. It's fine for it to be split into 2 messages, for example
"You use %d charges"
"You fail to modify %s"
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
There is very strange bug now (I guess it is related to damaged clothes and removed sewing tools charges): Occasionally filament/materials appear in crafting selection menu as they are nearby player, though filament is only in inventory of the player (see GIF below). It seems nearby materials disappear from crafting menu after I remove all modifications from the item. |
This comment has been minimized.
This comment has been minimized.
|
I've set breakpoint in the debugger to line 821 in crafting.cpp. Locals tab in VS shows that both
|
This comment has been minimized.
This comment has been minimized.
|
It seems issue was caused by non-integer double consumption_modifier = 1;
...
consumption_modifier = 1/2;
...
p->consume_items(it, consumption_modifier);Did I forgot some cast and 1/2 became 0? |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
Thanks a lot! I should've learn a bit about types in c++ before typing on my keyboard :) #include <iostream>
#include <typeinfo>
int main()
{
double a;
a = 1;
std::cout << typeid(a).name() << std::endl;
std::cout << a << std::endl;
a = 1/2;
std::cout << typeid(a).name() << std::endl;
std::cout << a << std::endl;
a = 0.5;
std::cout << typeid(a).name() << std::endl;
std::cout << a << std::endl;
}
|
Coolthulhu
reviewed
Mar 23, 2017
| p->add_msg_if_player(m_info, | ||
| _("You have used %d thread charges."), roll == SUCCESS ? filament_required : 1); | ||
| for (const auto &it : roll == SUCCESS ? req_success.get_components() : req.get_components() ) { | ||
| p->consume_items(it); |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Mar 23, 2017
Contributor
Try this with more than one thread type. For example, one thread in inventory and one on the floor and also yarn on the floor.
If this asks for thread type more than once, it is unacceptable.
This comment has been minimized.
This comment has been minimized.
ZhilkinSerg
Mar 23, 2017
Author
Contributor
Game asks for components each repair tick now - I know that's very bad and I will change that.
This comment has been minimized.
This comment has been minimized.
|
Any word on reasons for failed commits? Attempting to view details is returning a 404 error. |
This comment has been minimized.
This comment has been minimized.
|
It's says |
This comment has been minimized.
This comment has been minimized.
|
@ZhilkinSerg please make use of the online linter: http://dev.narc.ro/cataclysm/format.html |
This comment has been minimized.
This comment has been minimized.
|
I've updated Lint rules should be updated with:
Lint rules update was not commited yet. |
This comment has been minimized.
This comment has been minimized.
|
It was been over a month since last commit, and you were unable or unwilling to make use of the online linter? I have would attempted a pull request superseding this, had I not had difficulty understanding the code well enough to resolve the utterly unworkable problem of it prompting for thread every repair tick. |
This comment has been minimized.
This comment has been minimized.
|
Online linter won't help - it simply doesn't contain new rule for the change i did in The issue with prompting for components each tick happened to be not so easy to fix, otherwise I would've been resolved it already. Recently I've found possible way to avoid it. We need to use same approach as done in crafting - components are cached and crafting is done without asking until these cached components are available. See craft_command::execute() method. |
BevapDin
reviewed
Sep 24, 2017
| const inventory &crafting_inv = pl.crafting_inventory(); | ||
| const int req_amount = fix.volume() / 125_ml; | ||
| for( auto const &requirement : requirements ) { | ||
| auto req_id = requirement_id( requirement ); |
This comment has been minimized.
This comment has been minimized.
BevapDin
Sep 24, 2017
Contributor
This copy is pointless, requirement is already an requirement id. Just use it directly or change the loop variable to req_id.
BevapDin
reviewed
Sep 24, 2017
| const int req_amount = fix.volume() / 125_ml; | ||
|
|
||
| for( auto const &requirement : requirements ) { | ||
| auto req_id = requirement_id( requirement ); |
This comment has been minimized.
This comment has been minimized.
BevapDin
reviewed
Sep 24, 2017
| } | ||
| return false; | ||
| } | ||
|
|
||
| if( !requirements.empty() ) | ||
| { |
This comment has been minimized.
This comment has been minimized.
BevapDin
reviewed
Sep 24, 2017
| } | ||
|
|
||
| JsonArray jarr_requirements = obj.get_array("requirements"); | ||
| if (!jarr_requirements.empty()) { |
This comment has been minimized.
This comment has been minimized.
BevapDin
Sep 24, 2017
Contributor
This check is redundant. The following loop will work just fine with an empty array.
This comment has been minimized.
This comment has been minimized.
|
Any progress on this? |
This comment has been minimized.
This comment has been minimized.
Sorry, only rebasing occasionally. Have no time to work on that issue with asking of components each repair tick yet. I'm not dropping this change though and will continue working on it. |
This comment has been minimized.
This comment has been minimized.
|
This will close #20983, I believe. Be sure to add to issue description if so. |
This comment has been minimized.
This comment has been minimized.
|
@ZhilkinSerg Are you working on this? |

ZhilkinSerg commentedMar 16, 2017
•
edited
Overview of the changes:
generic_filament;advanced sewingaction to usefilamentrequirement added earlier;tailorprofession starting items (removedscissors, changedthreadquanity);repairaction to usefilamentrequirement when using tools withsewingquality for repair.To-do: