"install": "I",
"wear": "W",
"consume": "C",
+ "spin": "S",
"help": "h",
"toggle_map_mode": "L",
"toggle_tile_draw": "m",
'thing_id': t.id_,
'status': 'player'
}
+ game.io.send('PLAYER_ID %s' % t.id_, connection_id)
game.io.send('LOGIN_OK', connection_id)
t.name = nick
game.io.send('CHAT ' + quote(t.name + ' entered the map.'))
- game.io.send('PLAYER_ID %s' % t.id_, connection_id)
for s in [s for s in game.things
if s.type_ == 'SpawnPoint' and s.name == t.name]:
t.position = s.position
break
- game.changed = True
+ # game.changed = True # handled by game.add_thing
cmd_LOGIN.argtypes = 'string'
def cmd_BECOME_ADMIN(game, password, connection_id):
if not t:
raise GameError('thing of ID %s not found' % thing_id)
t.protection = protection_char
- #game.changed = True
+ game.changed = True
+ # FIXME: pseudo-FOV-change actually
+ game.record_fov_change(t.position)
cmd_THING_PROTECTION.argtypes = 'int:pos char'
def cmd_SET_MAP_CONTROL_PASSWORD(game, tile_class, password, connection_id):
t.name = nick
game.io.send('CHAT ' + quote(old_nick + ' renamed themselves to ' + nick))
game.changed = True
+ # FIXME: pseudo-FOV-change actually
+ game.record_fov_change(t.position)
cmd_NICK.argtypes = 'string'
def cmd_GET_GAMESTATE(game, connection_id):
if big_yx not in game.annotations:
game.annotations[big_yx] = {}
game.annotations[big_yx][little_yx] = msg
+ # FIXME: pseudo-FOV-change actually
+ game.record_fov_change([big_yx, little_yx])
game.changed = True
cmd_ANNOTATE.argtypes = 'yx_tuple:nonneg string string'
if big_yx not in game.portals:
game.portals[big_yx] = {}
game.portals[big_yx][little_yx] = msg
+ # FIXME: pseudo-FOV-change actually
+ game.record_fov_change([big_yx, little_yx])
game.changed = True
cmd_PORTAL.argtypes = 'yx_tuple:nonneg string string'
raise GameError('illegal thing type %s' % thing_type)
_ = game.get_map(big_yx)
game.add_thing(thing_type, (big_yx, little_yx), id_=thing_id)
- game.changed = True
+ # game.changed = True handled by add_thing
cmd_THING.argtypes = 'yx_tuple yx_tuple:nonneg string:thing_type int:nonneg'
def cmd_THING_NAME(game, thing_id, name, pw, connection_id):
raise GameError('wrong password for thing')
t.name = name
game.changed = True
+ # FIXME: pseudo-FOV-change actually
+ game.record_fov_change(t.position)
cmd_THING_NAME.argtypes = 'int:pos string string'
def cmd_GOD_THING_NAME(game, thing_id, name):
raise GameError('wrong face string length')
game.faces[t.name] = face
game.changed = True
+ # FIXME: pseudo-FOV-change actually
+ game.record_fov_change(t.position)
cmd_PLAYER_FACE.argtypes = 'string'
def cmd_GOD_PLAYER_FACE(game, name, face):
"""Send out game state data relevant to clients."""
# TODO: limit to connection_id if provided
- self.io.send('TURN ' + str(self.turn))
from plomrogue.mapping import FovMap
import multiprocessing
- c_ids = [c_id for c_id in self.sessions]
+ if connection_id:
+ c_ids = [connection_id]
+ else:
+ c_ids = [c_id for c_id in self.sessions]
# Only recalc FOVs for players with ._fov = None
player_fovs = []
player_fov_ids = []
player = self.get_thing(id_)
player._fov = new_fovs[i]
for c_id in c_ids:
+ self.io.send('TURN ' + str(self.turn), c_id)
player = self.get_player(c_id)
- self.io.send('FOV %s' % quote(player.fov_stencil.terrain), c_id)
- self.io.send('MAP %s %s %s' % (self.get_map_geometry_shape(),
- player.fov_stencil.geometry.size,
- quote(player.visible_terrain)), c_id)
- self.io.send('MAP_CONTROL %s' % quote(player.visible_control), c_id)
- seen_things = [t for t in self.things
- if player.fov_test(*t.position)]
- for t in seen_things:
- target_yx = player.fov_stencil.target_yx(*t.position)
- self.io.send('THING %s %s %s %s %s %s'
- % (target_yx, t.type_, quote(t.protection), t.id_,
- int(t.portable), int(t.commandable)),
- c_id)
- if hasattr(t, 'name'):
- self.io.send('THING_NAME %s %s' % (t.id_, quote(t.name)), c_id)
- if t.type_ == 'Player' and t.name in self.hats:
- hat = self.hats[t.name]
- self.io.send('THING_HAT %s %s' % (t.id_, quote(hat)), c_id)
- face = self.get_face(t)
- if face:
- self.io.send('THING_FACE %s %s' % (t.id_, quote(face)), c_id)
- if hasattr(t, 'thing_char'):
- self.io.send('THING_CHAR %s %s' % (t.id_,
- quote(t.thing_char)), c_id)
- if hasattr(t, 'installable') and not t.portable:
- self.io.send('THING_INSTALLED %s' % (t.id_), c_id)
- if hasattr(t, 'design'):
- self.io.send('THING_HAT %s %s' % (t.id_,
- quote(t.design)), c_id)
- for t in [t for t in seen_things if t.carrying]:
- # send this last so all carryable things are already created
- self.io.send('THING_CARRYING %s %s' % (t.id_, t.carrying.id_),
- c_id)
- for big_yx in self.portals:
- for little_yx in [little_yx for little_yx in self.portals[big_yx]
- if player.fov_test(big_yx, little_yx)]:
- target_yx = player.fov_stencil.target_yx(big_yx, little_yx)
- portal = self.portals[big_yx][little_yx]
- self.io.send('PORTAL %s %s' % (target_yx, quote(portal)), c_id)
- for big_yx in self.annotations:
- for little_yx in [little_yx for little_yx in self.annotations[big_yx]
- if player.fov_test(big_yx, little_yx)]:
- target_yx = player.fov_stencil.target_yx(big_yx, little_yx)
- annotation = self.annotations[big_yx][little_yx]
- self.io.send('ANNOTATION %s %s' % (target_yx,
- quote(annotation)), c_id)
- self.io.send('GAME_STATE_COMPLETE')
+ if player.id_ in player_fov_ids:
+ self.io.send('FOV %s' % quote(player.fov_stencil.terrain), c_id)
+ self.io.send('MAP %s %s %s' % (self.get_map_geometry_shape(),
+ player.fov_stencil.geometry.size,
+ quote(player.visible_terrain)), c_id)
+ self.io.send('MAP_CONTROL %s' % quote(player.visible_control), c_id)
+ if player.id_ in player_fov_ids:
+ # FIXME: Many of the following updates are triggered by technically
+ # inappropriate calls to game.record_fov_change, since they depict
+ # states that might change independent of FOV changes. They are
+ # collected here as a shortcut, but a cleaner way would be to
+ # differentiate the changes somehow.
+ self.io.send('PSEUDO_FOV_WIPE', c_id)
+ for t in player.seen_things:
+ target_yx = player.fov_stencil.target_yx(*t.position)
+ self.io.send('THING %s %s %s %s %s %s'
+ % (target_yx, t.type_, quote(t.protection), t.id_,
+ int(t.portable), int(t.commandable)),
+ c_id)
+ if hasattr(t, 'name'):
+ self.io.send('THING_NAME %s %s' % (t.id_, quote(t.name)), c_id)
+ if t.type_ == 'Player' and t.name in self.hats:
+ hat = self.hats[t.name]
+ self.io.send('THING_HAT %s %s' % (t.id_, quote(hat)), c_id)
+ face = self.get_face(t)
+ if face:
+ self.io.send('THING_FACE %s %s' % (t.id_, quote(face)), c_id)
+ if hasattr(t, 'thing_char'):
+ self.io.send('THING_CHAR %s %s' % (t.id_,
+ quote(t.thing_char)), c_id)
+ if hasattr(t, 'installable') and not t.portable:
+ self.io.send('THING_INSTALLED %s' % (t.id_), c_id)
+ if hasattr(t, 'design'):
+ self.io.send('THING_HAT %s %s' % (t.id_,
+ quote(t.design)), c_id)
+ for t in [t for t in player.seen_things if t.carrying]:
+ # send this last so all carryable things are already created
+ self.io.send('THING_CARRYING %s %s' % (t.id_, t.carrying.id_),
+ c_id)
+ for big_yx in self.portals:
+ for little_yx in [little_yx for little_yx in self.portals[big_yx]
+ if player.fov_test(big_yx, little_yx)]:
+ target_yx = player.fov_stencil.target_yx(big_yx, little_yx)
+ portal = self.portals[big_yx][little_yx]
+ self.io.send('PORTAL %s %s' % (target_yx, quote(portal)), c_id)
+ for big_yx in self.annotations:
+ for little_yx in [little_yx for little_yx in self.annotations[big_yx]
+ if player.fov_test(big_yx, little_yx)]:
+ target_yx = player.fov_stencil.target_yx(big_yx, little_yx)
+ annotation = self.annotations[big_yx][little_yx]
+ self.io.send('ANNOTATION %s %s' % (target_yx,
+ quote(annotation)), c_id)
+ self.io.send('GAME_STATE_COMPLETE', c_id)
def record_fov_change(self, position):
big_yx, little_yx = position
self.changed_tiles += [self.map_geometry.undouble_yxyx(big_yx,
little_yx)]
+ self.changed = True
def run_tick(self):
to_delete = []
to_delete += [connection_id]
for connection_id in to_delete:
del self.sessions[connection_id]
- self.changed = True
+ # self.changed = True already handled by remove_thing
for t in [t for t in self.things]:
if t in self.things:
try:
to_pick_up.position = self.thing.position[:]
self.thing.carrying = to_pick_up
to_pick_up.carried = True
+ # FIXME: pseudo-FOV-change actually
+ self.thing.game.record_fov_change(self.thing.position)
and t.position == dropped.position]:
t.accept(dropped)
break
+ # FIXME: pseudo-FOV-change actually
+ self.thing.game.record_fov_change(self.thing.position)
self.thing.send_msg('RANDOM_COLORS')
self.thing.send_msg('CHAT "You are drunk now."')
self.thing.drunk = 10000
- self.thing.invalidate_map_view()
+ # FIXME: pseudo-FOV-change actually
+ self.thing.game.record_fov_change(self.thing.position)
else:
self._get_uninstallables()[0].uninstall()
self.thing.send_msg('CHAT "You uninstall the thing here."')
+ # FIXME: pseudo-FOV-change actually
+ self.thing.game.record_fov_change(self.thing.position)
self.thing.send_msg('CHAT "You put on a hat."')
self.thing.game.remove_thing(self.thing.carrying)
self.thing.carrying = None
+ # FIXME: pseudo-FOV-change actually
+ self.thing.game.record_fov_change(self.thing.position)
if t != self and t.position == self.position]:
return
self.game.add_thing(self.child_type, self.position)
- self.game.changed = True
+ # self.game.changed = True handled by add_thing
hat.design = new_design
self.sound('HAT REMIXER', 'remixing a hat …')
self.game.changed = True
+ # FIXME: pseudo-FOV-change actually
+ self.game.record_fov_change(self.thing.position)
elif choice == 'Hat':
msg += 'pick it up and then use "(un-)wear" on it!'
self.sound('BOTTLE DEPOSITOR', msg)
- self.game.changed = True
+ # self.game.changed = True done by game.add_thing
def accept(self):
self.bottle_counter += 1
self._fov = None
self._visible_terrain = None
self._visible_control = None
+ self._seen_things = None
def set_next_task(self, task_name, args=()):
task_class = self.game.tasks[task_name]
# TODO: refactor with self.send_msg
self.game.io.send('DEFAULT_COLORS', c_id)
self.game.io.send('CHAT "You sober up."', c_id)
- self.invalidate_map_view()
+ #self.invalidate_map_view()
+ # FIXME: pseudo-FOV-change actually
+ self.game.record_fov_change(self.thing.position)
break
self.game.changed = True
if self.task is None:
self._visible_control = self.fov_stencil_map('control')
return self._visible_control
+ @property
+ def seen_things(self):
+ if self._seen_things is not None:
+ return self._seen_things
+ self._seen_things = [t for t in self.game.things
+ if self.fov_test(*t.position)]
+ return self._seen_things
class Thing_Player(ThingAnimate):
if (tokens[0] === 'TURN') {
game.turn_complete = false;
game.turn = parseInt(tokens[1]);
+ } else if (tokens[0] === 'PSEUDO_FOV_WIPE') {
+ game.portals_new = {};
+ explorer.annotations_new = {};
+ game.things_new = [];
} else if (tokens[0] === 'THING') {
let t = game.get_thing_temp(tokens[4], true);
t.position = parser.parse_yx(tokens[1]);
game.terrains[tokens[1]] = tokens[2]
} else if (tokens[0] === 'MAP') {
game.map_geometry_new = tokens[1];
- tui.init_keys();
game.map_size_new = parser.parse_yx(tokens[2]);
game.map_new = tokens[3]
} else if (tokens[0] === 'FOV') {
} else if (tokens[0] === 'MAP_CONTROL') {
game.map_control_new = tokens[1]
} else if (tokens[0] === 'GAME_STATE_COMPLETE') {
- game.turn_complete = true;
game.portals = game.portals_new;
- game.portals_new = {};
game.map_geometry = game.map_geometry_new;
game.map_size = game.map_size_new;
game.map = game.map_new;
+ tui.init_keys();
game.map_control = game.map_control_new;
explorer.annotations = explorer.annotations_new;
- explorer.annotations_new = {};
explorer.info_cached = false;
game.things = game.things_new;
- game.things_new = [];
game.player = game.things[game.player_id];
+ game.turn_complete = true;
if (tui.mode.name == 'post_login_wait') {
tui.switch_mode('play');
} else {
game.turn_complete = False
cmd_TURN.argtypes = 'int:nonneg'
+def cmd_PSEUDO_FOV_WIPE(game):
+ game.portals_new = {}
+ game.annotations_new = {}
+ game.things_new = []
+cmd_PSEUDO_FOV_WIPE.argtypes = ''
+
def cmd_LOGIN_OK(game):
game.tui.switch_mode('post_login_wait')
game.tui.send('GET_GAMESTATE')
cmd_MAP_CONTROL.argtypes = 'string'
def cmd_GAME_STATE_COMPLETE(game):
- game.turn_complete = True
game.tui.do_refresh = True
game.tui.info_cached = None
game.things = game.things_new
- game.things_new = []
game.portals = game.portals_new
- game.portals_new = {}
game.annotations = game.annotations_new
- game.annotations_new = {}
game.fov = game.fov_new
game.map_geometry = game.map_geometry_new
game.map_content = game.map_content_new
game.map_control_content = game.map_control_content_new
game.player = game.get_thing(game.player_id)
+ game.turn_complete = True
if game.tui.mode.name == 'post_login_wait':
game.tui.switch_mode('play')
cmd_GAME_STATE_COMPLETE.argtypes = ''
self.register_command(cmd_REPLY)
self.register_command(cmd_PLAYER_ID)
self.register_command(cmd_TURN)
+ self.register_command(cmd_PSEUDO_FOV_WIPE)
self.register_command(cmd_THING)
self.register_command(cmd_THING_TYPE)
self.register_command(cmd_THING_NAME)