home · contact · privacy
Make windows block sound.
[plomrogue2] / plomrogue / commands.py
index 65b054019b0f38dbb6d492803ec72e821baff28f..a92359eac8c2fcab197ea9ea42d2cd2de72b9a40 100644 (file)
@@ -44,7 +44,8 @@ def cmd_ALL(game, msg, connection_id):
     if not speaker:
         raise GameError('need to be logged in for this')
     largest_audible_distance = 20
-    dijkstra_map = DijkstraMap(game.maps, speaker.position,
+    things = [t for t in game.things if t.type_ != 'Player']
+    dijkstra_map = DijkstraMap(things, game.maps, speaker.position,
                                largest_audible_distance, game.get_map)
     for c_id in game.sessions:
         listener = game.get_player(c_id)
@@ -79,7 +80,7 @@ def cmd_LOGIN(game, nick, connection_id):
     t = game.thing_types['Player'](game)
     t.position = game.spawn_point
     game.things += [t]  # TODO refactor into Thing.__init__?
-    t.player_char = game.get_next_player_char()
+    t.thing_char = game.get_next_player_char()
     game.sessions[connection_id] = {
         'thing_id': t.id_,
         'status': 'player'
@@ -88,6 +89,10 @@ def cmd_LOGIN(game, nick, 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
 cmd_LOGIN.argtypes = 'string'
 
@@ -118,6 +123,19 @@ def cmd_SET_TILE_CONTROL(game, yx, control_char, connection_id):
     game.changed = True
 cmd_SET_TILE_CONTROL.argtypes = 'yx_tuple:nonneg char'
 
+def cmd_THING_PROTECTION(game, thing_id, protection_char, connection_id):
+    player = game.get_player(connection_id)
+    if not player:
+        raise GameError('need to be logged in for this')
+    if not game.sessions[connection_id]['status'] == 'admin':
+        raise GameError('need to be admin for this')
+    t = game.get_thing(thing_id)
+    if not t:
+        raise GameError('thing of ID %s not found' % thing_id)
+    t.protection = protection_char
+    game.changed = True
+cmd_THING_PROTECTION.argtypes = 'int:pos char'
+
 def cmd_SET_MAP_CONTROL_PASSWORD(game, tile_class, password, connection_id):
     player = game.get_player(connection_id)
     if not player:
@@ -237,7 +255,10 @@ def cmd_MAP_LINE(game, big_yx, y, line):
 cmd_MAP_LINE.argtypes = 'yx_tuple int:nonneg string'
 
 def cmd_MAP(game, geometry, size):
-    map_geometry_class = globals()['MapGeometry' + geometry]
+    from plomrogue.mapping import MapGeometryHex, MapGeometrySquare
+    map_geometry_class = MapGeometrySquare
+    if geometry == 'Hex':
+        map_geometry_class = MapGeometryHex
     game.new_world(map_geometry_class(size))
 cmd_MAP.argtypes = 'string:map_geometry yx_tuple:pos'
 
@@ -266,9 +287,38 @@ def cmd_THING(game, big_yx, little_yx, thing_type, thing_id):
     game.changed = True
 cmd_THING.argtypes = 'yx_tuple yx_tuple:nonneg string:thing_type int:nonneg'
 
-def cmd_THING_NAME(game, thing_id, name):
+def cmd_THING_NAME(game, thing_id, name, pw, connection_id):
+    # TODO check if thing in FOV
     t = game.get_thing(thing_id)
     if not t:
         raise GameError('thing of ID %s not found' % thing_id)
+    if not game.can_do_thing_with_pw(t, pw):
+        raise GameError('wrong password for tile')
     t.name = name
-cmd_THING_NAME.argtypes = 'int:pos string'
+    game.changed = True
+cmd_THING_NAME.argtypes = 'int:pos string string'
+
+def cmd_GOD_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_GOD_THING_NAME.argtypes = 'int:pos string'
+
+def cmd_GOD_THING_PROTECTION(game, thing_id, protection_char):
+    t = game.get_thing(thing_id)
+    if not t:
+        raise GameError('thing of ID %s not found' % thing_id)
+    t.protection = protection_char
+cmd_GOD_THING_PROTECTION.argtypes = 'int:pos char'
+
+def cmd_THING_DOOR_CLOSED(game, thing_id):
+    t = game.get_thing(thing_id)
+    if not t:
+        raise GameError('thing of ID %s not found' % thing_id)
+    if not t.type_ == 'Door':
+        raise GameError('thing of ID %s not door' % thing_id)
+    t.blocking = True
+    t.portable = False
+    t.thing_char = '#'
+cmd_THING_DOOR_CLOSED.argtypes = 'int:pos'