diff --git a/assets/cubyz/tools/axe.zig.zon b/assets/cubyz/tools/axe.zig.zon index 96aa3d66..b7f7f8e0 100644 --- a/assets/cubyz/tools/axe.zig.zon +++ b/assets/cubyz/tools/axe.zig.zon @@ -26,6 +26,7 @@ 0x0, 0x0, 0x0, 0x0, 1.0, }, .factor = 0.25, + .method = .average, }, .{ .source = .density, @@ -38,6 +39,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = 0.4, + .method = .average, }, .{ .source = .hardness, @@ -50,6 +52,7 @@ 0x0, 0x0, 0x0, 0x0, 1.0, }, .factor = 120, + .method = .average, }, .{ .source = .hardness, @@ -62,6 +65,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = 0.3, + .method = .average, }, .{ .source = .elasticity, @@ -74,6 +78,7 @@ 0x0, 0x0, 0x0, 0x0, 1.5, }, .factor = 120, + .method = .average, }, .{ .source = .elasticity, @@ -86,6 +91,7 @@ 0x0, 0x0, 0x0, 0x0, 0.5, }, .factor = -1.0, + .method = .average, }, }, } diff --git a/assets/cubyz/tools/pickaxe.zig.zon b/assets/cubyz/tools/pickaxe.zig.zon index 1e1c61e9..c813cbad 100644 --- a/assets/cubyz/tools/pickaxe.zig.zon +++ b/assets/cubyz/tools/pickaxe.zig.zon @@ -26,6 +26,7 @@ 0x0, 0x0, 0x0, 0x0, 1.0, }, .factor = 0.25, + .method = .average, }, .{ .source = .density, @@ -38,6 +39,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = 0.8, + .method = .average, }, .{ .source = .hardness, @@ -50,6 +52,7 @@ 0x0, 0x0, 0x0, 0x0, 0.5, }, .factor = 120, + .method = .average, }, .{ .source = .hardness, @@ -62,6 +65,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = 0.7, + .method = .average, }, .{ .source = .elasticity, @@ -74,6 +78,7 @@ 0x0, 0x0, 0x0, 0x0, 1.5, }, .factor = 120, + .method = .average, }, .{ .source = .elasticity, @@ -86,6 +91,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = -1.0, + .method = .average, }, }, } diff --git a/assets/cubyz/tools/shover.zig.zon b/assets/cubyz/tools/shover.zig.zon index a8e6c1cc..cbfa8be3 100644 --- a/assets/cubyz/tools/shover.zig.zon +++ b/assets/cubyz/tools/shover.zig.zon @@ -26,6 +26,7 @@ 0x0, 0x0, 0x0, 0x0, 1.0, }, .factor = 0.25, + .method = .average, }, .{ .source = .density, @@ -38,6 +39,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = 0.4, + .method = .average, }, .{ .source = .hardness, @@ -50,6 +52,7 @@ 0x0, 0x0, 0x0, 0x0, 1.0, }, .factor = 120, + .method = .average, }, .{ .source = .hardness, @@ -62,6 +65,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = 0.2, + .method = .average, }, .{ .source = .elasticity, @@ -74,6 +78,7 @@ 0x0, 0x0, 0x0, 0x0, 1.0, }, .factor = 120, + .method = .average, }, .{ .source = .elasticity, @@ -86,6 +91,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = -1.0, + .method = .average, }, }, } diff --git a/assets/cubyz/tools/sickle.zig.zon b/assets/cubyz/tools/sickle.zig.zon index 62fbc5e5..7eb8a4e7 100644 --- a/assets/cubyz/tools/sickle.zig.zon +++ b/assets/cubyz/tools/sickle.zig.zon @@ -26,6 +26,7 @@ 0x0, 0x0, 0x0, 0x0, 1.0, }, .factor = 0.25, + .method = .average, }, .{ .source = .density, @@ -38,6 +39,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = 0.8, + .method = .average, }, .{ .source = .hardness, @@ -50,6 +52,7 @@ 0x0, 0x0, 0x0, 0x0, 1.0, }, .factor = 120, + .method = .average, }, .{ .source = .hardness, @@ -62,6 +65,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = 0.7, + .method = .average, }, .{ .source = .elasticity, @@ -74,6 +78,7 @@ 0x0, 0x0, 0x0, 0x0, 1.5, }, .factor = 120, + .method = .average, }, .{ .source = .elasticity, @@ -86,6 +91,7 @@ 0x0, 0x0, 0x0, 0x0, 0.0, }, .factor = -1.0, + .method = .average, }, }, } diff --git a/src/items.zig b/src/items.zig index 0409224a..626825fb 100644 --- a/src/items.zig +++ b/src/items.zig @@ -398,7 +398,12 @@ const ToolPhysics = struct { // MARK: ToolPhysics weight += property.weigths[i]; } if(weight == 0) continue; - sum /= weight; + switch(property.method) { + .sum => {}, + .average => { + sum /= weight; + }, + } sum *= property.resultScale; tool.getProperty(property.destination orelse continue).* += sum; } @@ -443,6 +448,19 @@ const PropertyMatrix = struct { // MARK: PropertyMatrix destination: ?ToolProperty, weigths: [25]f32, resultScale: f32, + method: Method, + + const Method = enum { + average, + sum, + + fn fromString(string: []const u8) ?Method { + return std.meta.stringToEnum(Method, string) orelse { + std.log.err("Couldn't find property matrix method {s}.", .{string}); + return null; + }; + } + }; }; pub const ToolType = struct { // MARK: ToolType @@ -947,6 +965,7 @@ pub fn registerTool(assetFolder: []const u8, id: []const u8, zon: ZonElement) vo val.source = MaterialProperty.fromString(paramZon.get([]const u8, "source", "not specified")); val.destination = ToolProperty.fromString(paramZon.get([]const u8, "destination", "not specified")); val.resultScale = paramZon.get(f32, "factor", 1.0); + val.method = PropertyMatrix.Method.fromString(paramZon.get([]const u8, "method", "not specified")) orelse .sum; const matrixZon = paramZon.getChild("matrix"); for(0..25) |i| { val.weigths[i] = matrixZon.getAtIndex(f32, i, 0.0);