92 lines
1.5 KiB
Python
92 lines
1.5 KiB
Python
N = get_world_size()
|
|
|
|
def within(p, r):
|
|
return (
|
|
r[0] <= p[0] and
|
|
p[0] < r[1] and
|
|
r[2] <= p[1] and
|
|
p[1] < r[3]
|
|
)
|
|
|
|
def mv(tx, ty, wrap=False):
|
|
x = get_pos_x()
|
|
if wrap:
|
|
east_step = (tx + N - x) % N
|
|
west_step = (x + N - tx) % N
|
|
|
|
if east_step < west_step:
|
|
for i in range(east_step):
|
|
if not move(East):
|
|
return False
|
|
else:
|
|
for i in range(west_step):
|
|
if not move(West):
|
|
return False
|
|
else:
|
|
for i in range(max(0, tx-x)):
|
|
if not move(East):
|
|
return False
|
|
for i in range(max(0, x-tx)):
|
|
if not move(West):
|
|
return False
|
|
|
|
y = get_pos_y()
|
|
|
|
if wrap:
|
|
north_step = (ty + N - y) % N
|
|
south_step = (y + N - ty) % N
|
|
|
|
if north_step < south_step:
|
|
for i in range(north_step):
|
|
if not move(North):
|
|
return False
|
|
else:
|
|
for i in range(south_step):
|
|
if not move(South):
|
|
return False
|
|
else:
|
|
for i in range(max(0, ty-y)):
|
|
if not move(North):
|
|
return False
|
|
for i in range(max(0, y-ty)):
|
|
if not move(South):
|
|
return False
|
|
|
|
return True
|
|
|
|
def water():
|
|
if get_water() < 0.5:
|
|
use_item(Items.Water)
|
|
|
|
def grass():
|
|
typ = get_ground_type()
|
|
if typ != Grounds.Grassland:
|
|
till()
|
|
|
|
def soil():
|
|
typ = get_ground_type()
|
|
if typ != Grounds.Soil:
|
|
till()
|
|
|
|
def harv():
|
|
if can_harvest():
|
|
harvest()
|
|
return True
|
|
return False
|
|
|
|
def replant(entity):
|
|
typ = get_entity_type()
|
|
if typ != entity:
|
|
harvest()
|
|
plant(entity)
|
|
|
|
def spawn(func, x=0, y=0):
|
|
mv(x, y)
|
|
spawn_drone(func)
|
|
|
|
def meas(arg=None):
|
|
ret = None
|
|
while ret == None:
|
|
ret = measure(arg)
|
|
return ret
|