Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Replaces the existing calcTotalrecursive-Method
- function calcTotalRecursive() {
- try {
- if (DEVMODE_FUNCTION) {
- var trackingHandle = tracking.start("berater", "calcTotalRecursive", [recursionCount]);
- }
- totalRecursive = new Array(new Object(), new Object(), new Object(), new Object());
- // Type is set to '1', so only forestry products are inspected
- var type = 1;
- // Iterate over all products starting with those which are no pre-product. It is important that an inspected product won't be needed by a non-yet-inspected product!
- for (var i = prodNameSort[type].length - 1; i >= 0; i--) {
- // Id of currently inspected product
- var id = prodNameSort[type][i];
- // If this product is directly or recursivly needed...
- if (prodMinRack[type][id] > 0 || totalRecursive[type][id] > 0) {
- // If this product requires other products... (e.g. tree logs DON'T!)
- if (prodRequire[type][id]) {
- // Iterate over pre-products
- for (var j = 0; j < prodRequire[type][id].length; j++) {
- // Cache the currently inspected pre-product
- var req = prodRequire[type][id][j];
- if (!totalRecursive[req[0]][req[1]]) {
- // Initialize result storage of pre-product, if necessary
- totalRecursive[req[0]][req[1]] = 0;
- }
- /**
- Some magic is done here:
- - At first, we add the directly and recursivly needed products. If the latter not initialized, we assume 0.
- - Second, we divide the sum by the amount yielded product per production cycle, e.g. a 'Waschzuber' is 1 and 'Bretter (Gemeine Fichte)' is 5.
- - Third, we (should) multiply the result by the amount of products needed to initiate the production process.
- - Fourth, we round up to the next integer, because we can't spend fractions of pre-products.
- - At last, we sometimes don't want to round to the next integer, but to the next number e.g. dividable by 5. For instance, the
- production process of 30 'Bonbons' needs 5 'Honig' to start. The formula therefore would be: Math.ceil(x / 5) * 5, where
- x is our result of third. As the mathematicians might have recognized, we can reduce req[2] (amount of products needed to
- initiate the production process).
- */
- totalRecursive[req[0]][req[1]] += Math.ceil((prodMinRack[type][id] + (totalRecursive[type][id] ? totalRecursive[type][id] : 0)) / prodYield[type][id]) * req[2]; // Anzahl rekursiv benötigte Stämme = (direkt + rekursiv benötigte Bretter) / Bretter je Stamm
- }
- }
- }
- }
- if (DEVMODE_FUNCTION) {
- tracking.end("berater", trackingHandle);
- }
- } catch (err) {
- GM_logError("calcTotalRecursive\ntype=" + type + " iProd=" + iProd + " help=" + implode(help) + " i=" + i + "\n" + err);
- }
- }
- // German menu-item translation in function startScript()
- texte["de"]["settings_valMinRackRecursive"] = ["Rekursive Produkte", "Berechne die rekursiv benötigten Produkte (in der Baumerei) und addiere sie zur Liste der (direkt) benötigten Produkte hinzu."];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement