Greetings.
I’ve coded myself into a corner here, because I am nowhere near a good enough programmer to figure this out on my own, apparently, and I am requesting some qualified advice to help me get over this hurdle.
Here’s what I am doing.
I’m rewriting the code that loads, processes, and displays crafting recipes, plus everything that the changes involved affect.
More specifically, I am changing the way recipe JSONs are written (while keeping the ability to load them the “old” way), so that it can allow tool-quality requirements to be optional, as well as allow them to require charges, and generally generalize the “recipe requirement” concept.
Segueing out of that is my rewriting of the function that processes the recipe and determines if the player has enough tools and components to craft it. And therein lies a snag.
My idea of doing this involves iterating through the items in the provided inventory. However, the “items” array (vector, set, whichever it is… map?) is private to the Inventory class, presumably for a good reason, so I can’t mimic the original function, and have to actually pass the processing over into a function in the Inventory class. I am reasonably sure that the code I wrote for the function is, in principle, at least capable of working to some extent. But this involves passing the actual recipe list - or, well, a pointer(reference?) to the recipe list, so that the function can assign values to the variables inside the various recipe requirements.
So the question is - how do I do this, exactly?
The pick_recipes function is where the call to the function originates:
With crafting_inv being a const inventory& crafting_inv, and *iter is recipe_list::iterator iter.
can_make_with_inventory is a bool game::can_make_with_inventory(recipe *r, const inventory &crafting_inv). It calls a bool inventory::can_make_recipe(recipe r) function, via return crafting_inv.can_make_recipe®;
How do I set up the can_make_recipe function, how do I call it in these circumstances, and how do I address the variables of r within it (i.e. r.variable or r->variable) so that it properly operates on the original recipe list, rather than a copy or who knows what else?
Any and all help greatly appreciated.