Merge branch 'master' of ctpug.org.za:tabakrolletjie
[tabakrolletjie.git] / tabakrolletjie / lights.py
index b2e081201ae27bf9113146ba4a3106389a4bda44..fef2b44d2133e32c2f43d2e1366ad00101e8559e 100644 (file)
@@ -1,6 +1,8 @@
 """ May it be a light for you in dark places, when all other lights go out.
 """
 
+import math
+
 import pymunk
 import pymunk.pygame_util
 import pygame.display
@@ -83,6 +85,9 @@ class LightManager(object):
             if light.on and light.ray_manager.reaches(shape.body.position)
         ]
 
+    def total_power_usage(self):
+        return sum(light.power_usage() for light in self._lights)
+
     def render_light(self, surface):
         for light in self._lights:
             light.render_light(surface)
@@ -209,8 +214,8 @@ class BaseLight(object):
 
             if ncolour == 1:
                 self._fitting_image = loader.load_image(
-                "48", self.FITTING_IMG,
-                transform=Multiply(colour=fitting_colours[0]))
+                    "48", self.FITTING_IMG,
+                    transform=Multiply(colour=fitting_colours[0]))
             else:
                 if self._colour_mult_image is None:
                     self._colour_mult_image = pygame.surface.Surface((48, 48))
@@ -219,8 +224,8 @@ class BaseLight(object):
                         sector = loader.load_image(
                             "48", "light_mask_%d_%d.png" % (ncolour, i + 1),
                             transform=Multiply(colour=fitting_colours[i]))
-                        self._colour_mult_image.blit(sector, (0,0), None, 0)
-                    
+                        self._colour_mult_image.blit(sector, (0, 0), None, 0)
+
                 self._fitting_image = loader.load_image(
                     "48", self.FITTING_IMG,
                     transform=MultiplyImage(image=self._colour_mult_image))
@@ -234,6 +239,16 @@ class BaseLight(object):
         rx, ry = self.ray_manager.pygame_position(surface)
         surface.blit(self.fitting_image(), (rx - 24, ry - 24), None, 0)
 
+    def power_usage(self):
+        if not self.on:
+            return 0.0
+        area = math.pi * (self.ray_manager.max_radius ** 2)  # radius
+        area = area * (self.ray_manager.spread / (2 * math.pi))  # spread
+        return 5 * area * self.intensity / 6400  # 80x80 unit area
+
+    def base_damage(self):
+        return 5 * self.intensity
+
     def toggle(self):
         self.colour_pos += 1
         if self.colour_pos >= len(self.colour_cycle):