Ejemplo n.º 1
0
    def __draw_world_tile(self, item):
        ###########################################################################
        draw_mode = curr_draw_mode()

        if (draw_mode == DrawMode.LAND):
            self.__draw_land(item)

        elif (draw_mode == DrawMode.CIV):
            self.__draw_land(item)
            if (item.city() is not None):
                self._draw_with_offset("misc", "city.jpg", (50, 50), (25, 25))

                self._print_with_offset("Size: %d" % item.city().rank(), _RED,
                                        (30, 75))

            elif (item.infra_level() is not None and item.infra_level() > 0):
                image = "farm.jpg" if (item.yield_().food > 0) else "mine.jpg"

                self._draw_with_offset("misc", image, (50, 50), (25, 25))

                self._print_with_offset("Level: %d" % item.infra_level(),
                                        _YELLOW, (30, 75))

        elif (is_geological(draw_mode)):
            self.draw(item.geology())

        elif (is_atmospheric(draw_mode)):
            self.__draw_land(item)
            self.draw(item.atmosphere())

        else:
            self.__draw_land_property(draw_mode, item)

        self.__x_pos += 100
Ejemplo n.º 2
0
    def __draw_geology(self, item):
        ###########################################################################
        draw_mode = curr_draw_mode()
        prequire(is_geological(draw_mode), "Bad draw mode ", draw_mode)

        self._draw_with_offset("geology",
                               item.__class__.__name__.lower() + ".jpg",
                               (100, 100))

        # Figure out what string to print and what color it should be
        if (draw_mode == DrawMode.GEOLOGY):
            pass  # already drawn
        elif (draw_mode in [DrawMode.TENSION, DrawMode.MAGMA]):
            value = item.tension() if draw_mode == DrawMode.TENSION \
                else item.magma()
            to_draw = ("%.3f" % value)

            if (value < .333):
                color = _GREEN
            elif (value < .666):
                color = _YELLOW
            else:
                color = _RED

            self._print_with_offset(to_draw, color, (30, 40))
        else:
            prequire(False, "Should not draw geology in mode: ", draw_mode)
Ejemplo n.º 3
0
    def __draw_geology(self, item):
    ###########################################################################
        draw_mode = curr_draw_mode()
        prequire(is_geological(draw_mode), "Bad draw mode ", draw_mode)
        expected_length = self.TILE_TEXT_WIDTH

        # Figure out what string to print and what color it should be
        if (draw_mode == DrawMode.GEOLOGY):
            color, symbol = self._GEOLOGY_MAP[item.__class__]

            to_draw = symbol.center(expected_length)
        elif (draw_mode in [DrawMode.TENSION, DrawMode.MAGMA]):
            value = item.tension() if draw_mode == DrawMode.TENSION \
               else item.magma()
            to_draw = ("%.3f" % value).center(expected_length)

            if (value < .333):
                color = GREEN
            elif (value < .666):
                color = YELLOW
            else:
                color = RED
        else:
            prequire(False, "Should not draw geology in mode: ", draw_mode)

        prequire(len(to_draw) == self.TILE_TEXT_WIDTH,
                 "Symbol '", to_draw, "' is wrong length")

        cprint(color, to_draw)
Ejemplo n.º 4
0
    def __draw_atmosphere(self, item):
    ###########################################################################
        draw_mode = curr_draw_mode()

        field = self.__get_field_for_draw_mode(item, draw_mode)
        color = self.__compute_atmos_color(draw_mode, field)
        str_  = str(field).center(self.TILE_TEXT_WIDTH)

        cprint(color, str_)
Ejemplo n.º 5
0
    def __draw_atmosphere(self, item):
        ###########################################################################
        draw_mode = curr_draw_mode()

        field = self.__get_field_for_draw_mode(item, draw_mode)
        color = self.__compute_color(draw_mode, field, self._ATMOS_COLOR_MAP)

        to_draw = ("%.2f" % field)

        self._print_with_offset(to_draw, color, (30, 40))
Ejemplo n.º 6
0
    def __draw_world(self, item):
        ###########################################################################
        draw_mode = curr_draw_mode()

        self.draw(item.time())

        self.__world_dim = (item.width(), item.height())

        self.__tile_start_pos = (self.__x_pos, self.__y_pos)

        # Draw tiles
        for row in item.iter_rows():
            for tile in row:
                self.__draw_world_tile(tile)
            self.__x_pos = 0
            self.__y_pos += 100
Ejemplo n.º 7
0
    def __draw_world(self, item):
    ###########################################################################
        real_draw_mode = curr_draw_mode()

        self.draw(item.time())
        print()

        # Make room for row labels
        print("  ", end="")

        # Draw column labels. Need to take 1 char space separator into account.
        for col_id in xrange(item.width()):
            print(("%d" % col_id).center(self.TILE_TEXT_WIDTH), end=" ")
        print()

        # Draw tiles
        for row_id, row in enumerate(item.iter_rows()):
            for height in xrange(self.TILE_TEXT_HEIGHT):
                # Middle of tile displays "overlay" info, for the rest
                # of the tile, just draw the land.
                if (height == self.TILE_TEXT_HEIGHT / 2):
                    draw_mode = real_draw_mode
                    print(row_id, end=" ") # row label
                else:
                    draw_mode = DrawMode.LAND
                    print("  ", end="") # no label

                # Draw tiles
                for tile in row:
                    self.__draw_world_tile(tile, mode_override=draw_mode)
                    print(" ", end="") # col separator

                print()

            print()

        # Draw recent anomalies
        for anomaly in item.iter_anomalies():
            self.draw(anomaly)
            print()
Ejemplo n.º 8
0
    def __draw_world_tile(self, item, mode_override=None):
    ###########################################################################
        if (mode_override is None):
            draw_mode = curr_draw_mode()
        else:
            draw_mode = mode_override

        if (draw_mode == DrawMode.LAND):
            self.__draw_land(item)

        elif (draw_mode == DrawMode.CIV):
            if (item.city() is not None):
                cprint(RED, " C: ",
                       str(item.city().rank()).center(self.TILE_TEXT_WIDTH-4))
            elif (item.infra_level() is not None and item.infra_level() > 0):
                cprint(YELLOW, " I: ",
                       str(item.infra_level()).center(self.TILE_TEXT_WIDTH-4))
            else:
                self.__draw_land(item)

        elif (draw_mode == DrawMode.MOISTURE):
            moisture = item.soil_moisture()
            if (moisture is not None):
                if (moisture < 1.0):
                    color = YELLOW
                elif (moisture < get_flooding_threshold()):
                    color = GREEN
                elif (moisture < get_totally_flooded_threshold()):
                    color = BLUE
                else:
                    color = RED
                cprint(color, "%.3f" % moisture)
            else:
                self.__draw_land(item)

        elif (draw_mode == DrawMode.YIELD):
            yield_ = item.yield_()
            if (yield_.food > 0):
                cprint(GREEN, "%.3f" % yield_.food)
            else:
                cprint(RED, "%.3f" % yield_.prod)

        elif (draw_mode == DrawMode.ELEVATION):
            elevation = item.elevation()
            if (elevation is not None):
                if (elevation < 2500):
                    color = GREEN
                elif (elevation < 7000):
                    color = YELLOW
                else:
                    color = WHITE
                cprint(color, ("%d" % elevation).center(self.TILE_TEXT_WIDTH))
            else:
                self.__draw_land(item)

        elif (draw_mode == DrawMode.SNOWPACK):
            snowpack = item.snowpack()
            if (snowpack is not None):
                if (snowpack < 12):
                    color = YELLOW
                elif (snowpack < 40):
                    color = BLUE
                else:
                    color = WHITE
                cprint(color, ("%.1f" % snowpack).center(self.TILE_TEXT_WIDTH))
            else:
                self.__draw_land(item)

        elif (draw_mode == DrawMode.SEASURFACETEMP):
            sea_surface_temp = item.sea_surface_temp()
            if (sea_surface_temp is not None):
                if (sea_surface_temp < 65):
                    color = BLUE
                elif (sea_surface_temp < 80):
                    color = YELLOW
                else:
                    color = RED
                cprint(color, "%.2f" % sea_surface_temp)
            else:
                self.__draw_land(item)

        elif (is_geological(draw_mode)):
            self.draw(item.geology())

        elif (is_atmospheric(draw_mode)):
            self.draw(item.atmosphere())

        else:
            prequire(False, "Unhandled mode: ", draw_mode)