View difference between Paste ID: bUmZQVgW and cJQYigeR
SHOW: | | - or go back to the newest paste.
1
// Replaces the existing calcTotalrecursive-Method
2
function calcTotalRecursive() {
3
    var type, id, req, i, j;
4
    try {
5-
            var trackingHandle = tracking.start("berater", "calcTotalRecursive", [recursionCount]);
5+
6
            var trackingHandle = tracking.start("berater", "calcTotalRecursive", []);
7
        }
8
9-
        var type = 1;
9+
10
        // Type is set to '1', so only forestry products are inspected
11-
        for (var i = prodNameSort[type].length - 1; i >= 0; i--) {
11+
        type = 1;
12
13-
            var id = prodNameSort[type][i];
13+
14
        for (i = prodNameSort[type].length - 1; i >= 0; i--) {
15
            // Id of currently inspected product
16
            id = prodNameSort[type][i];
17
18
            // If this product is directly or recursivly needed...
19-
                    for (var j = 0; j < prodRequire[type][id].length; j++) {
19+
20
                // If this product requires other products... (e.g. tree logs DON'T!)
21-
                        var req = prodRequire[type][id][j];
21+
22
                    // Iterate over pre-products
23
                    for (j = 0; j < prodRequire[type][id].length; j++) {
24
                        // Cache the currently inspected pre-product
25
                        req = prodRequire[type][id][j];
26
                        if (!totalRecursive[req[0]][req[1]]) {
27-
                    Some magic is done here:
27+
28-
                    - At first, we add the directly and recursivly needed products. If the latter not initialized, we assume 0.
28+
29-
                    - 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.
29+
30-
                    - Third, we (should) multiply the result by the amount of products needed to initiate the production process.
30+
31-
                    - Fourth, we round up to the next integer, because we can't spend fractions of pre-products.
31+
32-
                    - 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
32+
                    	 * Some real magic is done here: We calculate, how many pre-products are recursivly needed!
33-
                        production process of 30 'Bonbons' needs 5 'Honig' to start. The formula therefore would be: Math.ceil(x / 5) * 5, where
33+
                    	 * - At first, we add the directly and recursivly needed products. If the latter not initialized, we assume 0.
34-
                        x is our result of third. As the mathematicians might have recognized, we can reduce req[2] (amount of products needed to
34+
                    	 * - Second, we divide the sum by the amount yielded product per production cycle, e.g. a 'Waschzuber' is 1 and 'Bretter (Gemeine
35-
                        initiate the production process).
35+
                    	 *		Fichte)' is 5.
36-
                    */
36+
                    	 * - Third, we (should) multiply the result by the amount of products needed to initiate the production process.
37
                    	 * - Fourth, we round up to the next integer, because we can't spend fractions of pre-products.
38
                    	 * - 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
39
                         * 		production process of 30 'Bonbons' needs 5 'Honig' to start. The formula therefore would be: Math.ceil(x / 5) * 5, where
40
                         * 		x is our result of third. As the mathematicians might have recognized, we can reduce req[2] (amount of products needed to
41
                         * 		initiate the production process).
42
                    	 */
43
                        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
44
                    }
45
                }
46-
        GM_logError("calcTotalRecursive\ntype=" + type + " iProd=" + iProd + " help=" + implode(help) + " i=" + i + "\n" + err);
46+
47
        }
48
        if (DEVMODE_FUNCTION) {
49
            tracking.end("berater", trackingHandle);
50
        }
51
    } catch (err) {
52
        GM_logError("calcTotalRecursive\ntype=" + type + " id=" + id + " req=" + implode(req) + " i=" + i + " j=" + j + "\n" + err);
53
    }
54
}
55
56
// In 'function calcProdMinRack(caller)', the call of calcTotalRecursive must be fitted to the new signiture
57
if (valMinRackRecursive) {
58
	calcTotalRecursive(); // recursive need products calculation
59
	// Some iteration over variable totalRecursive to adjust prodMinRack
60
}
61
62
// German menu-item translation in function startScript()
63
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."];