Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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_orthogonal = @import("on_orthogonal.zig");
52 changes: 52 additions & 0 deletions src/proceduralItem/modifiers/restrictions/on_orthogonal.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_orthogonal = struct {
tag: main.Tag,
amount: usize,
range: ?usize,
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.

Fixed range restrictions will be supported with #3092, please remove this parameter

};

pub fn satisfied(self: *const On_orthogonal, proceduralItem: *const ProceduralItem, x: i32, y: i32) bool {
var count: usize = 0;
const gridSize: usize = proceduralItem.materialGrid.len - 1;
const rangeChecked = @min(self.range orelse gridSize, gridSize);
const lowBound = 0;
const highBound = rangeChecked*2 + 1;
for (lowBound..highBound) |dx| {
const checkedX = x + (@as(i32, @intCast(dx)) - rangeChecked);
const checkedY = y + (@as(i32, @intCast(0)) - rangeChecked);
if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1;
}
for (lowBound..highBound) |dy| {
const checkedX = x + (@as(i32, @intCast(0)) - rangeChecked);
const checkedY = y + (@as(i32, @intCast(dy)) - rangeChecked);
if (dy != 0) { // prevents double counting
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_orthogonal {
const result = allocator.create(On_orthogonal);
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_orthogonal, outString: *main.List(u8)) void {
if (self.range == null) {
outString.print("{} .{s} {s}", .{self.amount, self.tag.getName(), "on orthoganal axis"});
} else {
outString.print("{} .{s} {s} {?}", .{self.amount, self.tag.getName(), "in orthoganal range", self.range});
}
}
Loading