home · contact · privacy
Improve volume logic, display.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 12 Nov 2020 10:18:04 +0000 (11:18 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 12 Nov 2020 10:18:04 +0000 (11:18 +0100)
plomrogue/commands.py
plomrogue/mapping.py

index a3d1f4ce685cfabb9f6108ff8bd7f0f154e8434b..ccc09c0c8f945a92d1fee3d16f375c93882d6980 100644 (file)
@@ -18,10 +18,18 @@ def cmd_ALL(game, msg, connection_id):
         listener = game.get_thing(game.sessions[c_id], create_unfound=False)
         d_y = abs(speaker.position.y - listener.position.y)
         d_x = abs(speaker.position.x - listener.position.x)
-        d = math.sqrt(d_y ** 2 + d_x ** 2)
-        distance = '(close)' if d < 3 else '(distant)'
+        distance = math.sqrt(d_y ** 2 + d_x ** 2)
+        fov_overlap = 1
+        if listener.fov_stencil[speaker.position] != '.':
+            fov_overlap_tiles = 0
+            for i in range(speaker.fov_stencil.size_i):
+                if speaker.fov_stencil.terrain[i] == '.' and\
+                   listener.fov_stencil.terrain[i] == '.':
+                    fov_overlap_tiles += 1
+            fov_overlap = fov_overlap_tiles / speaker.fov_stencil.size_i
+        volume = fov_overlap / max(1, distance)
         game.io.send('CHAT ' +
-                     quote('%s %s: %s' % (distance, speaker.nickname, msg)),
+                     quote('(volume: %.3f) %s: %s' % (volume, speaker.nickname, msg)),
                      c_id)
 cmd_ALL.argtypes = 'string'
 
index 4f2f5f9e3b7c465bc05ed1409af9b318befb8d71..10f9b70a5c1dbe9975e11d4233ba56aad80368d6 100644 (file)
@@ -149,7 +149,7 @@ class FovMap(Map):
     def __init__(self, source_map, center):
         self.source_map = source_map
         self.size = self.source_map.size
-        self.fov_radius = (self.size.y / 2) - 0.5
+        self.fov_radius = 12 # (self.size.y / 2) - 0.5
         self.start_indented = True  #source_map.start_indented
         self.terrain = '?' * self.size_i
         self.center = center