Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a5d158f
Added OnDiagonal
Crepestrom Mar 7, 2026
f581ab0
oops thats a special casing
Crepestrom Mar 7, 2026
edb1abd
Update _list.zig capilat
Crepestrom Mar 7, 2026
a5293f4
Apply suggestion from @IntegratedQuantum
Crepestrom Mar 14, 2026
4bf0e91
renaming and default checking whole axis
Crepestrom Mar 15, 2026
36c1fd0
new dault is 0
Crepestrom Mar 15, 2026
7d2db02
Update onDiagonal.zig
Crepestrom Mar 15, 2026
ceb9edd
formatting
Crepestrom Mar 15, 2026
e652631
Update onDiagonal.zig
Crepestrom Mar 15, 2026
6961efd
tabs not spaces
Crepestrom Mar 16, 2026
937795e
Update onDiagonal.zig
Crepestrom Mar 16, 2026
c15af76
Apply suggestion from @IntegratedQuantum
Crepestrom Mar 16, 2026
e8f0d89
Update src/tool/modifiers/restrictions/onDiagonal.zig
Crepestrom Mar 16, 2026
89885a4
Update onDiagonal.zig
Crepestrom Mar 17, 2026
8541037
Update onDiagonal.zig
Crepestrom Mar 17, 2026
ff712a0
Update onDiagonal.zig
Crepestrom Mar 17, 2026
3236b0c
Update onDiagonal.zig
Crepestrom Mar 17, 2026
72ddac2
Update onDiagonal.zig
Crepestrom Mar 17, 2026
80bd149
Update onDiagonal.zig
Crepestrom Apr 4, 2026
c635b94
Update onDiagonal.zig
Crepestrom Apr 12, 2026
8fcb2ea
Merge remote-tracking branch 'upstream/master' into Modifier-OnDiagonal
Crepestrom Apr 12, 2026
6228f4b
pocerdural item not a tool
Crepestrom Apr 12, 2026
d5a005e
uuuh what?
Crepestrom Apr 18, 2026
419198f
dgdfg
Crepestrom Apr 18, 2026
91f1537
Revert "dgdfg"
Crepestrom Apr 18, 2026
cf9e81c
Revert "uuuh what?"
Crepestrom Apr 18, 2026
f92a2b3
Merge remote-tracking branch 'upstream/master' into Modifier-OnDiagonal
Crepestrom Apr 18, 2026
62f64fb
on_diagonal but nt
Crepestrom Apr 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/proceduralItem/modifiers/restrictions/_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub const @"and" = @import("and.zig");
pub const encased = @import("encased.zig");
pub const not = @import("not.zig");
pub const @"or" = @import("or.zig");
pub const on_diagonal = @import("on_diagonal.zig");
52 changes: 52 additions & 0 deletions src/proceduralItem/modifiers/restrictions/on_diagonal.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const std = @import("std");

const main = @import("main");
const NeverFailingAllocator = main.heap.NeverFailingAllocator;
const ModifierRestriction = main.items.ModifierRestriction;
const ProceduralItem = main.items.ProceduralItem;
const ZonElement = main.ZonElement;

const On_diagonal = struct {
tag: main.Tag,
amount: usize,
range: ?usize,
};

pub fn satisfied(self: *const On_diagonal, proceduralItem: *const ProceduralItem, x: i32, y: i32) bool {
var count: usize = 0;
const gridSize: usize = proceduralItem.craftingGrid.len;
const rangeChecked = @min(self.range orelse 5, gridSize);
const lowBound = 0;
const highBound = rangeChecked*2 + 1;
for (lowBound..highBound) |dx| {
const checkedX = x + @as(i32, @intCast(dx - rangeChecked));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a crash

Suggested change
const checkedX = x + @as(i32, @intCast(dx - rangeChecked));
const checkedX = x + @as(i32, @intCast(dx)) - rangeChecked;

const checkedY = y + @as(i32, @intCast(dx - rangeChecked));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong, using dx for y. Also dx convention is for delta values, but only dx - rangedCheck is the actual delta.
I'd suggest to rename it.

if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the dx != 0 check from below

}
for (lowBound..highBound) |dx| {
const checkedX = x + @as(i32, @intCast(dx - rangeChecked));
const checkedY = y - @as(i32, (@intCast(dx - rangeChecked)));
if (dx != 0) {
if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1;
}
}
return count >= self.amount;
}

pub fn loadFromZon(allocator: NeverFailingAllocator, zon: ZonElement) *const On_diagonal {
const result = allocator.create(On_diagonal);
result.* = .{
.tag = main.Tag.find(zon.get([]const u8, "tag", "not specified")),
.amount = zon.get(usize, "amount", 8),
.range = zon.get(?usize, "range", null),
};
return result;
}

pub fn printTooltip(self: *const On_diagonal, outString: *main.List(u8)) void {
if (self.range == null) {
outString.print("{} .{s} {s}", .{self.amount, self.tag.getName(), "on diagonal axis"});
} else {
outString.print("{} .{s} {s} {?}", .{self.amount, self.tag.getName(), "in diagonal range", self.range});
}
}
Loading