def cmd_THING_POS(game, i, yx):
t = game.world.get_thing(i)
- t.position = list(yx)
+ t.position = tuple(yx)
cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'
def cmd_THING_INVENTORY(game, id_, ids):
t = game.world.get_thing(id_)
- t.inventory = [ids] # TODO: test whether valid IDs
-cmd_THING_INVENTORY.argtypes = 'int:nonneg, seq:int:nonneg'
+ t.inventory = ids # TODO: test whether valid IDs
+cmd_THING_INVENTORY.argtypes = 'int:nonneg seq:int:nonneg'
def cmd_TERRAIN_LINE(game, y, terrain_line):
game.world.map_.set_line(y, terrain_line)
write(f, 'THING_TYPE %s %s' % (thing.id_, thing.type_))
write(f, 'THING_POS %s %s' % (thing.id_,
stringify_yx(thing.position)))
- write(f, 'THING_INVENTORY %s %s' %
- (thing.id_,','.join([str(i) for i in thing.inventory])))
+ if len(thing.inventory) > 0:
+ write(f, 'THING_INVENTORY %s %s' %
+ (thing.id_,','.join([str(i) for i in thing.inventory])))
+ else:
+ write(f, 'THING_INVENTORY %s ,' % thing.id_)
if hasattr(thing, 'task'):
task = thing.task
if task is not None:
from plomrogue.errors import ArgError
from plomrogue.commands import (cmd_GEN_WORLD, cmd_GET_GAMESTATE, cmd_MAP,
cmd_MAP, cmd_THING_TYPE, cmd_THING_POS,
+ cmd_THING_INVENTORY,
cmd_TERRAIN_LINE, cmd_PLAYER_ID, cmd_TURN,
cmd_SWITCH_PLAYER, cmd_SAVE)
from plomrogue.mapping import MapHex
def add_thing(type_):
t = self.game.thing_types[type_](self)
- t.position = [random.randint(0, yx[0] -1),
- random.randint(0, yx[1] - 1)]
+ t.position = (random.randint(0, yx[0] -1),
+ random.randint(0, yx[1] - 1))
self.things += [t]
return t
'MAP': cmd_MAP,
'THING_TYPE': cmd_THING_TYPE,
'THING_POS': cmd_THING_POS,
+ 'THING_INVENTORY': cmd_THING_INVENTORY,
'TERRAIN_LINE': cmd_TERRAIN_LINE,
'PLAYER_ID': cmd_PLAYER_ID,
'TURN': cmd_TURN,
"""Iterate over YX position coordinates."""
for y in range(self.size[0]):
for x in range(self.size[1]):
- yield [y, x]
+ yield (y, x)
def lines(self):
width = self.size[1]
class MapWithLeftRightMoves(Map):
def move_LEFT(self, start_pos):
- return [start_pos[0], start_pos[1] - 1]
+ return (start_pos[0], start_pos[1] - 1)
def move_RIGHT(self, start_pos):
- return [start_pos[0], start_pos[1] + 1]
+ return (start_pos[0], start_pos[1] + 1)
class MapSquare(MapWithLeftRightMoves):
def move_UP(self, start_pos):
- return [start_pos[0] - 1, start_pos[1]]
+ return (start_pos[0] - 1, start_pos[1])
def move_DOWN(self, start_pos):
- return [start_pos[0] + 1, start_pos[1]]
+ return (start_pos[0] + 1, start_pos[1])
def move_UPLEFT(self, start_pos):
if start_pos[0] % 2 == 1:
- return [start_pos[0] - 1, start_pos[1] - 1]
+ return (start_pos[0] - 1, start_pos[1] - 1)
else:
- return [start_pos[0] - 1, start_pos[1]]
+ return (start_pos[0] - 1, start_pos[1])
def move_UPRIGHT(self, start_pos):
if start_pos[0] % 2 == 1:
- return [start_pos[0] - 1, start_pos[1]]
+ return (start_pos[0] - 1, start_pos[1])
else:
- return [start_pos[0] - 1, start_pos[1] + 1]
+ return (start_pos[0] - 1, start_pos[1] + 1)
def move_DOWNLEFT(self, start_pos):
if start_pos[0] % 2 == 1:
- return [start_pos[0] + 1, start_pos[1] - 1]
+ return (start_pos[0] + 1, start_pos[1] - 1)
else:
- return [start_pos[0] + 1, start_pos[1]]
+ return (start_pos[0] + 1, start_pos[1])
def move_DOWNRIGHT(self, start_pos):
if start_pos[0] % 2 == 1:
- return [start_pos[0] + 1, start_pos[1]]
+ return (start_pos[0] + 1, start_pos[1])
else:
- return [start_pos[0] + 1, start_pos[1] + 1]
+ return (start_pos[0] + 1, start_pos[1] + 1)
def basic_circle_out_move(self, pos, direction):
"""Move position pos into direction. Return whether still in map."""
mover = getattr(self, 'move_' + direction)
- pos[:] = mover(pos)
+ pos = mover(pos)
if pos[0] < 0 or pos[1] < 0 or \
pos[0] >= self.size[0] or pos[1] >= self.size[1]:
- return False
- return True
+ return pos, False
+ return pos, True
def circle_out(self, yx, f):
# Optimization potential: Precalculate movement positions. (How to check
#print('DEBUG CIRCLE_OUT', yx)
while circle_in_map:
circle_in_map = False
- self.basic_circle_out_move(yx, 'RIGHT')
+ yx, _ = self.basic_circle_out_move(yx, 'RIGHT')
for dir_i in range(len(self.circle_out_directions)):
for dir_progress in range(distance):
direction = self.circle_out_directions[dir_i]
- if self.circle_out_move(yx, direction):
+ yx, test = self.circle_out_move(yx, direction)
+ if test:
f(yx, distance, dir_i, dir_progress)
circle_in_map = True
distance += 1