home · contact · privacy
Add terrain descriptions.
[plomrogue2] / plomrogue / commands.py
index 1c59abfd0b4ca9e4bcb82351297cf1bab59c321b..643988e63258a49480b185450a6d6632cfe86734 100644 (file)
@@ -4,7 +4,7 @@ from plomrogue.mapping import YX, MapGeometrySquare, MapGeometryHex, Map
 
 
 
-# TODO: instead of sending tasks and thing types on request, send them on connection
+# TODO: instead of sending tasks, thing types etc. on request, send them on connection
 
 def cmd_TASKS(game, connection_id):
     tasks = []
@@ -13,10 +13,16 @@ cmd_TASKS.argtypes = ''
 
 def cmd_THING_TYPES(game, connection_id):
     for t_t in game.thing_types.values():
-        game.io.send('THING_TYPE %s %s' % (t_t.get_type(), t_t.symbol_hint),
+        game.io.send('THING_TYPE %s %s' % (t_t.get_type(), quote(t_t.symbol_hint)),
                      connection_id)
 cmd_THING_TYPES.argtypes = ''
 
+def cmd_TERRAINS(game, connection_id):
+    for t in game.terrains.keys():
+        game.io.send('TERRAIN %s %s' % (quote(t), quote(game.terrains[t])),
+                     connection_id)
+cmd_TERRAINS.argtypes = ''
+
 def cmd_ALL(game, msg, connection_id):
 
     def lower_msg_by_volume(msg, volume):
@@ -67,7 +73,7 @@ def cmd_ALL(game, msg, connection_id):
         listener_vol = dijkstra_map[game.map.get_position_index(listener.position)]
         volume = 1 / max(1, listener_vol)
         lowered_msg = lower_msg_by_volume(msg, volume)
-        lowered_nick = lower_msg_by_volume(speaker.nickname, volume)
+        lowered_nick = lower_msg_by_volume(speaker.name, volume)
         game.io.send('CHAT ' +
                      quote('(volume: %.2f) %s: %s' % (volume, lowered_nick,
                                                       lowered_msg)),
@@ -75,30 +81,31 @@ def cmd_ALL(game, msg, connection_id):
 cmd_ALL.argtypes = 'string'
 
 def cmd_LOGIN(game, nick, connection_id):
-    for t in [t for t in game.things if t.type_ == 'Player' and t.nickname == nick]:
+    for t in [t for t in game.things if t.type_ == 'Player' and t.name == nick]:
         raise GameError('name already in use')
     if connection_id in game.sessions:
         raise GameError('cannot log in twice')
     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
-    game.io.send('CHAT ' + quote(t.nickname + ' entered the map.'))
+    t.name = nick
+    game.io.send('CHAT ' + quote(t.name + ' entered the map.'))
     game.io.send('PLAYER_ID %s' % t.id_, connection_id)
     game.changed = True
 cmd_LOGIN.argtypes = 'string'
 
 def cmd_NICK(game, nick, connection_id):
-    for t in [t for t in game.things if t.type_ == 'Player' and t.nickname == nick]:
+    for t in [t for t in game.things if t.type_ == 'Player' and t.name == nick]:
         raise GameError('name already in use')
     if not connection_id in game.sessions:
         raise GameError('can only rename when already logged in')
     t_id = game.sessions[connection_id]
     t = game.get_thing(t_id)
-    old_nick = t.nickname
-    t.nickname = nick
+    old_nick = t.name
+    t.name = nick
     game.io.send('CHAT ' + quote(old_nick + ' renamed themselves to ' + nick))
     game.changed = True
 cmd_NICK.argtypes = 'string'
@@ -111,8 +118,8 @@ cmd_GET_GAMESTATE.argtypes = ''
 #    if not connection_id in game.sessions:
 #        raise GameError('can only query when logged in')
 #    t = game.get_thing(game.sessions[connection_id], False)
-#    source_nick = t.nickname
-#    for t in [t for t in game.things if t.type_ == 'Player' and t.nickname == target_nick]:
+#    source_nick = t.name
+#    for t in [t for t in game.things if t.type_ == 'Player' and t.name == target_nick]:
 #        for c_id in game.sessions:
 #            if game.sessions[c_id] == t.id_:
 #                game.io.send('CHAT ' + quote(source_nick+ '->' + target_nick + ': ' + msg), c_id)
@@ -210,3 +217,10 @@ def cmd_THING(game, yx, thing_type, thing_id):
         game.things += [t_new]
     game.changed = True
 cmd_THING.argtypes = 'yx_tuple:nonneg string:thing_type int:nonneg'
+
+def cmd_THING_NAME(game, thing_id, name):
+    t = game.get_thing(thing_id)
+    if not t:
+        raise GameError('thing of ID %s not found' % thing_id)
+    t.name = name
+cmd_THING_NAME.argtypes = 'int:pos string'