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 atRange = @import("atRange.zig");
54 changes: 54 additions & 0 deletions src/proceduralItem/modifiers/restrictions/atRange.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 Encased = struct {
tag: main.Tag,
amount: usize,
range: usize,
};

pub fn satisfied(self: *const Encased, proceduralItem: *const ProceduralItem, x: i32, y: i32) bool {
var count: usize = 0;
const lowBound = 0;
const highBound = self.range*2 + 1;
for (lowBound..highBound) |dx| {
const checkedX = x + @as(i32, @intCast(dx - self.range));
const checkedY = y + @as(i32, @intCast(2));
if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1;
}
for (lowBound..highBound) |dx| {
const checkedX = x + @as(i32, @intCast(dx - self.range));
const checkedY = y + @as(i32, @intCast(-2));
if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1;
}
for ((lowBound + 1)..(highBound - 1)) |dy| {
const checkedX = x + @as(i32, @intCast(-2));
const checkedY = y + @as(i32, @intCast(dy - self.range));
if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1;
}
for ((lowBound + 1)..(highBound - 1)) |dy| {
const checkedX = x + @as(i32, @intCast(2));
const checkedY = y + @as(i32, @intCast(dy - self.range));
if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1;
}
return count >= self.amount;
}

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

pub fn printTooltip(self: *const Encased, outString: *main.List(u8)) void {
outString.print("{} .{s} {s} {}", .{self.amount, self.tag.getName(), "is at range", self.range});
}
Loading