1 from parser import ArgError
6 def __init__(self, map_classes):
7 """Collects tuple of basic Map[Geometry] classes."""
8 self.map_classes = map_classes
10 def get_map_geometries(self):
12 for map_class in self.map_classes:
13 geometries += [map_class.__name__[3:]]
16 def get_map_class(self, geometry):
17 for map_class in self.map_classes:
18 if map_class.__name__[3:] == geometry:
24 def __init__(self, size=(0, 0)):
26 self.terrain = '?'*self.size_i
30 return self.size[0] * self.size[1]
32 def set_line(self, y, line):
33 height_map = self.size[0]
34 width_map = self.size[1]
36 raise ArgError('too large row number %s' % y)
37 width_line = len(line)
38 if width_line > width_map:
39 raise ArgError('too large map line width %s' % width_line)
40 self.terrain = self.terrain[:y * width_map] + line +\
41 self.terrain[(y + 1) * width_map:]
43 def get_position_index(self, yx):
44 return yx[0] * self.size[1] + yx[1]
50 self.Thing = Thing # child classes may use an extended Thing class here
54 def get_thing(self, id_, create_unfound=True):
55 for thing in self.things:
59 t = self.Thing(self, id_)
64 def new_map(self, geometry, yx):
65 map_type = self.game.map_manager.get_map_class(geometry)
66 self.map_ = map_type(yx)
71 def __init__(self, world, id_):
78 class CommonCommandsMixin:
80 def cmd_MAP(self, geometry, yx):
81 """Create new map of grid geometry, size yx and only '?' cells."""
82 self.world.new_map(geometry, yx)
83 cmd_MAP.argtypes = 'string:geometry yx_tuple:pos'
85 def cmd_THING_TYPE(self, i, type_):
86 t = self.world.get_thing(i)
88 cmd_THING_TYPE.argtypes = 'int:nonneg string'
90 def cmd_THING_POS(self, i, yx):
91 t = self.world.get_thing(i)
93 cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'