t = game.thing_types['Player'](game)
t.position = YX(game.map.size.y // 2, game.map.size.x // 2)
game.things += [t] # TODO refactor into Thing.__init__?
+ t.player_char = game.get_next_player_char()
game.sessions[connection_id] = t.id_
game.io.send('LOGIN_OK', connection_id)
t.nickname = nick
from plomrogue.io import GameIO
from plomrogue.misc import quote
from plomrogue.mapping import YX, MapGeometrySquare, Map
+import string
self.map_control_passwords = {}
self.annotations = {}
self.portals = {}
+ self.player_chars = string.digits + string.ascii_letters
+ self.player_char_i = -1
if os.path.exists(self.io.save_file):
if not os.path.isfile(self.io.save_file):
raise GameError('save file path refers to non-file')
return True
def get_string_options(self, string_option_type):
- import string
if string_option_type == 'direction':
return self.map_geometry.get_directions()
elif string_option_type == 'char':
if hasattr(t, 'nickname'):
self.io.send('THING_NAME %s %s' % (t.id_,
quote(t.nickname)), c_id)
+ if hasattr(t, 'player_char'):
+ self.io.send('THING_CHAR %s %s' % (t.id_,
+ quote(t.player_char)), c_id)
for yx in [yx for yx in self.portals
if player.fov_stencil[yx] == '.']:
self.io.send('PORTAL %s %s' % (yx, quote(self.portals[yx])), c_id)
return 1
return max([t.id_ for t in self.things]) + 1
+ def get_next_player_char(self):
+ self.player_char_i += 1
+ if self.player_char_i >= len(self.player_chars):
+ self.player_char_i = 0
+ return self.player_chars[self.player_char_i]
+
def save(self):
def write(f, msg):
t.name = name
cmd_THING_NAME.argtypes = 'int:nonneg string'
+def cmd_THING_CHAR(game, thing_id, c):
+ t = game.get_thing(thing_id)
+ if t:
+ t.player_char = c
+cmd_THING_CHAR.argtypes = 'int:nonneg char'
+
def cmd_MAP(game, geometry, size, content):
map_geometry_class = globals()['MapGeometry' + geometry]
game.map_geometry = map_geometry_class(size)
self.register_command(cmd_THING)
self.register_command(cmd_THING_TYPE)
self.register_command(cmd_THING_NAME)
+ self.register_command(cmd_THING_CHAR)
self.register_command(cmd_MAP)
self.register_command(cmd_MAP_CONTROL)
self.register_command(cmd_PORTAL)
info = 'TERRAIN: %s\n' % self.game.map_content[pos_i]
for t in self.game.things:
if t.position == self.explorer:
- info += 'THING: %s' % t.type_
+ info += 'THING: %s / %s' % (t.type_,
+ self.game.thing_types[t.type_])
+ if hasattr(t, 'player_char'):
+ info += t.player_char
if hasattr(t, 'name'):
info += ' (name: %s)' % t.name
info += '\n'
used_positions = []
for t in self.game.things:
symbol = self.game.thing_types[t.type_]
+ meta_char = ' '
+ if hasattr(t, 'player_char'):
+ meta_char = t.player_char
if t.position in used_positions:
- map_lines_split[t.position.y][t.position.x] = symbol + '+'
- else:
- map_lines_split[t.position.y][t.position.x] = symbol + ' '
+ meta_char = '+'
+ map_lines_split[t.position.y][t.position.x] = symbol + meta_char
used_positions += [t.position]
if self.mode.shows_info:
map_lines_split[self.explorer.y][self.explorer.x] = '??'
if (t) {
t.name_ = tokens[2];
};
+ } else if (tokens[0] === 'THING_CHAR') {
+ let t = game.get_thing(tokens[1], false);
+ if (t) {
+ t.player_char = tokens[2];
+ };
} else if (tokens[0] === 'TASKS') {
game.tasks = tokens[1].split(',')
} else if (tokens[0] === 'THING_TYPE') {
for (const thing_id in game.things) {
let t = game.things[thing_id];
let symbol = game.thing_types[t.type_];
+ let meta_char = ' ';
+ if (t.player_char) {
+ meta_char = t.player_char;
+ }
if (used_positions.includes(t.position.toString())) {
- map_lines_split[t.position[0]][t.position[1]] = symbol + '+';
- } else {
- map_lines_split[t.position[0]][t.position[1]] = symbol + ' ';
+ meta_char = '+';
};
+ map_lines_split[t.position[0]][t.position[1]] = symbol + meta_char;
used_positions.push(t.position.toString());
};
}
for (let t_id in game.things) {
let t = game.things[t_id];
if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) {
- info += "THING: " + t.type_;
+ let symbol = game.thing_types[t.type_];
+ info += "THING: " + t.type_ + " / " + symbol;
+ if (t.player_char) {
+ info += t.player_char;
+ };
if (t.name_) {
info += " (name: " + t.name_ + ")";
}