From: adrianna Date: Fri, 16 Sep 2016 16:22:21 +0000 (+0200) Subject: mostly correct power usage in tooltips X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=29b77de055ab8bec00e97ea391bf538bc2c5e73a;p=tabakrolletjie.git mostly correct power usage in tooltips --- diff --git a/TODO.txt b/TODO.txt index 033052a..d360dad 100644 --- a/TODO.txt +++ b/TODO.txt @@ -10,7 +10,6 @@ Features * Maybe configure lights in separate json file, to allow reuse of consistent models in multiple levels? * Allow going down to zero seeds by buying lights if a turnip is planted * Maybe make the mould weaker at the start -* Display average power usage in light tooltip * Maybe also display information next to existing lights -- tooltip? * Generally balance the levels better and add more levels * Graphical level selection with screenshots @@ -50,3 +49,4 @@ Done * Different prices for different lights * Calculate both from # of colours, speed, beam width, etc.? * added tooltips for lights +* Display average power usage in light tooltip diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 06f84ba..c2e12e6 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -13,7 +13,7 @@ import pygame.transform from .constants import ( LIGHT_CATEGORY, FITTINGS_CATEGORY, OBSTACLE_CATEGORY, TURNIP_CATEGORY, - COLOURS) + COLOURS, FPS, NIGHT_HOURS_PER_TICK) from .rays import RayPolyManager from .utils import DetailedTimer from .loader import loader @@ -230,7 +230,16 @@ class BaseLight(object): @classmethod def get_info(cls, config): - return ["intensity: %g" % config["intensity"]] + spread = math.radians(config.get("spread", 360)) + rl = config.get("radius_limits", (0, 50.0)) + intensity = config["intensity"] + power_usage = (cls._power_usage(rl[0], rl[1], spread, intensity) + / (FPS * NIGHT_HOURS_PER_TICK)) + return [ + "power usage: %d/h" % power_usage, + "", + "intensity: %g" % intensity, + ] def add(self, space): if self.body.space is not None: @@ -310,13 +319,18 @@ class BaseLight(object): rx, ry = self.ray_manager.pygame_position(surface) surface.blit(self.fitting_image(), (rx - self.FITTING_RADIUS, ry - self.FITTING_RADIUS), None, 0) + @staticmethod + def _power_usage(min_radius, max_radius, spread, intensity): + area = math.pi * (max_radius ** 2 - min_radius ** 2) # radius + area = area * (spread / (2 * math.pi)) # spread + return 5 * area * intensity / 6400 # 80x80 unit area + def power_usage(self): if not self.on: return 0.0 rm = self.ray_manager - area = math.pi * (rm.max_radius ** 2 - rm.min_radius ** 2) # radius - area = area * (rm.spread / (2 * math.pi)) # spread - return 5 * area * self.intensity / 6400 # 80x80 unit area + power_usage = self._power_usage(rm.min_radius, rm.max_radius, rm.spread, self.intensity) + return power_usage def base_damage(self): return 10 * self.intensity @@ -403,11 +417,19 @@ class PulsatingLamp(BaseLight): @classmethod def get_info(cls, config): + spread = math.radians(config.get("spread", 360)) + rl = config.get("radius_limits", (0, 50.0)) pr = config.get("pulse_range", cls.DEFAULT_PULSE_RANGE) pv = config.get("pulse_velocity", cls.DEFAULT_PULSE_VELOCITY) ir = config.get("intensity_range", cls.DEFAULT_INTENSITY_RANGE) iv = config.get("intensity_velocity", cls.DEFAULT_INTENSITY_VELOCITY) + min_power = (cls._power_usage(rl[0], pr[0], spread, ir[0]) + / (FPS * NIGHT_HOURS_PER_TICK)) + max_power = (cls._power_usage(rl[0], pr[1], spread, ir[1]) + / (FPS * NIGHT_HOURS_PER_TICK)) return [ + "power usage: %d/h - %d/h" % (min_power, max_power), + "", "intensity: %g - %g, velocity %g" % (ir[0], ir[1], iv), "pulse: %d - %d, velocity %g" % (pr[0], pr[1], pv), ]