-
-
Notifications
You must be signed in to change notification settings - Fork 212
Added OnDiagonal Modifier [Modifier 2 of 4] #2693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a5d158f
f581ab0
edb1abd
a5293f4
4bf0e91
36c1fd0
7d2db02
ceb9edd
e652631
6961efd
937795e
c15af76
e8f0d89
89885a4
8541037
ff712a0
3236b0c
72ddac2
80bd149
c635b94
8fcb2ea
6228f4b
d5a005e
419198f
91f1537
cf9e81c
f92a2b3
62f64fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)); | ||
| const checkedY = y + @as(i32, @intCast(dx - rangeChecked)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks wrong, using dx for y. Also |
||
| if ((proceduralItem.getItemAt(checkedX, checkedY) orelse continue).hasTag(self.tag)) count += 1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing the |
||
| } | ||
| 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}); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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