add cactus utilities and grid-wide planting/harvesting logic

This commit is contained in:
2026-01-11 02:49:47 -05:00
parent 70caea1243
commit 4e774109ef
3 changed files with 273 additions and 3 deletions

View File

@@ -16,6 +16,50 @@ def move_to(x, y):
# Harvest all tiles in a grid.
#
# Returns:
# None
def harvest_grid(width, height):
res = {}
x = get_pos_x()
y = get_pos_y()
grid_size = get_world_size()
if (x + width) > grid_size:
width = grid_size - x
if (y + height) > grid_size:
height = grid_size - y
others = {East: West, West: East}
side_dir = East
for row in range(height):
for col in range(width):
if can_harvest():
harvest()
# if it's not the last pass, then move
if col < width - 1:
if side_dir == East:
x = (x + 1) % grid_size
elif side_dir == West:
x = (x - 1) % grid_size
move(side_dir)
if row < height - 1:
side_dir = others[side_dir]
move(North)
y = (y + 1) % grid_size
return res
# Plant a square of the given list of entities.
#
# If the water level is below waterBelow,
@@ -68,7 +112,10 @@ def plant_grid(width, height, plant_with, water_below, require_soil, on_plant =
index = tracker % len(plant_with)
tracker += 1
plant(plant_with[index])
success = plant(plant_with[index])
if not success:
print("Failed to plant at " + str(x) + ", " + str(y))
# if on_plant is not None: is giving me errors in the game, but this seems to be what they want
if on_plant: