Beispiel #1
0
 def show_planets(self):
     si_txt = Data_CONST.get_text_list('PLANET_SIZES')
     ty_txt = Data_CONST.get_text_list('PLANET_TYPES')
     mi_txt = Data_CONST.get_text_list('PLANET_MINERALS')
     te_txt = Data_CONST.get_text_list('PLANET_TERRAINS')
     print
     print(
         "+-----------+-----------------+----------+--------+---------------+------------+----------+------+---------+"
     )
     print(
         "| planet_id | star            | position | size   | type          | minerals   | terrain  | food | max pop |"
     )
     print(
         "+-----------+-----------------+----------+--------+---------------+------------+----------+------+---------+"
     )
     for i, p in self.d_planets.items():
         print(
             "| %9i | %15s | %8i | %6s | %13s | %10s | %8s | %4i | %7i |" %
             (i, self.d_stars[p.i_star_id].s_name, p.i_position,
              si_txt[p.i_size], ty_txt[p.i_type], mi_txt[p.i_minerals],
              te_txt[p.i_terrain], p.i_foodbase, p.i_max_population))
     print(
         "+-----------+-----------------+----------+--------+---------------+------------+----------+------+---------+"
     )
     print
Beispiel #2
0
 def show_stars(self):
     s_txt = Data_CONST.get_text_list('STAR_SIZES')
     c_txt = Data_CONST.get_text_list('STAR_CLASSES')
     print
     print("+---------+-----------------+------------+------------+--------+-------+-------+-------+-------+-------+")
     print("| star_id | name            | coords     | class      | size   | obj 1 | obj 2 | obj 3 | obj 4 | obj 5 |")
     print("+---------+-----------------+------------+------------+--------+-------+-------+-------+-------+-------+")
     for i, s in self.d_stars.items():
         obj = s.v_object_ids
         print("| %7i | %15s | %4i, %4i | %10s | %6s | %5i | %5i | %5i | %5i | %5i |" % (i, s.s_name, s.i_x, s.i_y, c_txt[s.i_class], s_txt[s.i_size], obj[0], obj[1], obj[2], obj[3], obj[4]))
     print("+---------+-----------------+------------+------------+--------+-------+-------+-------+-------+-------+")
Beispiel #3
0
def main(argv):
    """
        MAIN
    """
    MOO2_DIR = find_moo2_dir()

    if not MOO2_DIR:
        print("")
        print("ERROR: no MOO2 directory found")
        print("    OpenMOO2 requires original Master of Orion 2 game data to run, see README.TXT for more information")
        print("")
        sys.exit(1)

    default_options = {
        '-h':       "localhost",
        '-p':       9999,
        '-player':  0
    }

    (OPTIONS, PARAMS) = Game_Args.parse_cli_args(argv, default_options)

    HOST               = OPTIONS['-h']
    PORT               = OPTIONS['-p']
    PLAYER_ID          = OPTIONS['-player']
    SOCKET_BUFFER_SIZE = 4096

    GUI.init(MOO2_DIR)

    pygame.mouse.set_visible(False)
    pygame.display.set_caption("OpenMOO2: PLAYER_ID = %s" % PLAYER_ID)

    Data_BUILDINGS.regularize_building_keys()
    Data_CONST.regularize_government_keys()
    Data_TECH.regularize_tech_keys()

    Network_Client.Client.connect(HOST, PORT, SOCKET_BUFFER_SIZE)
    Network_Client.Client.login(PLAYER_ID)

#    Network_Client.Client.ping()
#    server_status = Network_Client.Client.get_server_status()
#    print("# server_status = %s" % str(server_status))


    # automation for development
#    scenario = autoplayer.AutoPlayer(CLIENT)
#    scenario.play()
#    sys.exit(0)

    #JWL#ICON = pygame.image.load(MOO2_DIR + "/orion2-icon.png")
    #JWL#pygame.display.set_icon(ICON)

    Gui.GUI.run()

    Network_Client.Client.disconnect()
Beispiel #4
0
 def show_planets(self):
     si_txt = Data_CONST.get_text_list('PLANET_SIZES')
     ty_txt = Data_CONST.get_text_list('PLANET_TYPES')
     mi_txt = Data_CONST.get_text_list('PLANET_MINERALS')
     te_txt = Data_CONST.get_text_list('PLANET_TERRAINS')
     print
     print("+-----------+-----------------+----------+--------+---------------+------------+----------+------+---------+")
     print("| planet_id | star            | position | size   | type          | minerals   | terrain  | food | max pop |")
     print("+-----------+-----------------+----------+--------+---------------+------------+----------+------+---------+")
     for i, p in self.d_planets.items():
         print("| %9i | %15s | %8i | %6s | %13s | %10s | %8s | %4i | %7i |" % (i, self.d_stars[p.i_star_id].s_name, p.i_position, si_txt[p.i_size], ty_txt[p.i_type], mi_txt[p.i_minerals], te_txt[p.i_terrain], p.i_foodbase, p.i_max_population))
     print("+-----------+-----------------+----------+--------+---------------+------------+----------+------+---------+")
     print
Beispiel #5
0
    def show_ships(self):
        print
        print("+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+")
        print("| ship_id | name             | owner           | status   | coords     | destination                | speed | turns |")
        print("+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+")
        for i, s in self.d_ships.items():
            if s.exists():
                i_dest_id          = s.i_dest_star_id
                o_dest_star        = self.d_stars[i_dest_id]
                s_dest_name        = o_dest_star.s_name
                i_dest_x, i_dest_y = o_dest_star.get_coords()
                o_owner            = self.d_players[s.i_owner_id]
                print("| %7i | %16s | %15s | %8s | %4i, %4i | [%3i, %3i] %15s | %5i | %5i |" % (i, s.s_name, o_owner.s_race_name, s.get_status_text(), s.i_x, s.i_y, i_dest_x, i_dest_y, s_dest_name, s.i_travelling_speed, s.i_turns_left))
        print("+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+")
        print

        sp_txt = Data_CONST.get_text_list('SHIP_SPECIALS')

        for i, s in self.d_ships.items():
            d_design = s.d_design
            print("    === ship_id # %i ===" % i)
            for i_dev_id in d_design['special_devices']:
                txt = sp_txt[i_dev_id] if (i_dev_id < sp_txt.__len__()) else '<out-of-range>'
                print("        special device: %2i ... %s" % (i_dev_id, txt))
            print
def main(argv):
    default_options = {
        '-g':   "SAVE1.GAM",
        '-h':	"localhost",
        '-p':	9999,
    }

    (OPTIONS, PARAMS) = Game_Args.parse_cli_args(argv, default_options)

    LISTEN_ADDR = OPTIONS['-h']
    LISTEN_PORT = OPTIONS['-p']
    GAME_FILE	= OPTIONS['-g']

    if GAME_FILE == '':
        show_usage(argv[0], "ERROR: Missing game file to load")
        sys.exit(1)

    print("* Init...")
    GAME = Game_Main.Game_Main(Game_Rules.DEFAULT_RULES)

    moo2_dir = openmoo2.find_moo2_dir()
    if moo2_dir is None:
        print "Error: MOO2 Game directory not found in ../, ../../ or ../../../"
        sys.exit(1)

    print("* Loading savegame from '%s/%s'" % (moo2_dir, GAME_FILE))

    Data_BUILDINGS.regularize_building_keys()
    Data_CONST.regularize_government_keys()
    Data_TECH.regularize_tech_keys()

    GAME.load_moo2_savegame(moo2_dir + "/" + GAME_FILE)
    GAME.show_stars()
    GAME.show_planets()
    GAME.show_players()
    GAME.show_colonies()
    GAME.show_ships()

    SERVER = Network_Server.Network_Server(LISTEN_ADDR, LISTEN_PORT, GAME)
    SERVER.s_name = GAME_FILE.split("/")[-1]

    print("* Run...")
    SERVER.run()

    print("* Exit...")
    sys.exit(0)
Beispiel #7
0
 def show_stars(self):
     s_txt = Data_CONST.get_text_list('STAR_SIZES')
     c_txt = Data_CONST.get_text_list('STAR_CLASSES')
     print
     print(
         "+---------+-----------------+------------+------------+--------+-------+-------+-------+-------+-------+"
     )
     print(
         "| star_id | name            | coords     | class      | size   | obj 1 | obj 2 | obj 3 | obj 4 | obj 5 |"
     )
     print(
         "+---------+-----------------+------------+------------+--------+-------+-------+-------+-------+-------+"
     )
     for i, s in self.d_stars.items():
         obj = s.v_object_ids
         print(
             "| %7i | %15s | %4i, %4i | %10s | %6s | %5i | %5i | %5i | %5i | %5i |"
             % (i, s.s_name, s.i_x, s.i_y, c_txt[s.i_class],
                s_txt[s.i_size], obj[0], obj[1], obj[2], obj[3], obj[4]))
     print(
         "+---------+-----------------+------------+------------+--------+-------+-------+-------+-------+-------+"
     )
    def draw(self):
        self.fill((0, 0, 0))
        self.blit_image((0, 0),   'info_screen', 'panel'),
        self.blit_image((21, 50), 'info_screen', 'button', 'history_graph',   'off'),
        self.blit_image((21, 77), 'info_screen', 'button', 'tech_review',     'off'),
        self.blit_image((21, 102),'info_screen', 'button', 'race_statistics', 'off'),
        self.blit_image((21, 128),'info_screen', 'button', 'turn_summary',    'off'),
        self.blit_image((21, 154),'info_screen', 'button', 'reference',       'off'),

        # grid behind
        self.blit_image((433, 115), 'app_pic', 0)

        # app image
        self.blit_image((433, 115), 'app_pic', 155)

        tech_carets = []

        if self.__tech_review == "achievements":

            v_known_techs = self.get_me().v_known_techs

            # New Construction Types
            items = []
            for tech_id in [K_TECH_PLANET_CONSTRUCTION, K_TECH_TITAN_CONTRUCTION, K_TECH_TRANSPORT, K_TECH_OUTPOST_SHIP, K_TECH_FREIGHTERS, K_TECH_COLONY_SHIP, K_TECH_COLONY_BASE]:
                if tech_id in v_known_techs:
                    items.append(tech_id)
            if len(items):
                tech_carets.append({'title': "New Construction Types", 'items': items})

            # Spies
            items = []
            for tech_id in [K_TECH_TELEPATHIC_TRAINING, K_TECH_NEURAL_SCANNER, K_TECH_SPY_NETWORK]:
                if tech_id in v_known_techs:
                    items.append(tech_id)
            if len(items):
                tech_carets.append({'title': "Spies", 'items': items})

        y = 64
        for caret in tech_carets:
            if len(caret['items']):
                self.write_text(K_FONT4, K_PALETTE_TECH, 223, y, caret['title'], 2)
                y += 16
                for item in caret['items']:
                    text = Data_CONST.get_text_list('TECH_LIST')[item]['name']
                    self.write_text(K_FONT3, K_PALETTE_TECH, 233, y, text, 2)
                    y += 13
                y += 6
Beispiel #9
0
    def show_ships(self):
        print
        print(
            "+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+"
        )
        print(
            "| ship_id | name             | owner           | status   | coords     | destination                | speed | turns |"
        )
        print(
            "+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+"
        )
        for i, s in self.d_ships.items():
            if s.exists():
                i_dest_id = s.i_dest_star_id
                o_dest_star = self.d_stars[i_dest_id]
                s_dest_name = o_dest_star.s_name
                i_dest_x, i_dest_y = o_dest_star.get_coords()
                o_owner = self.d_players[s.i_owner_id]
                print(
                    "| %7i | %16s | %15s | %8s | %4i, %4i | [%3i, %3i] %15s | %5i | %5i |"
                    % (i, s.s_name, o_owner.s_race_name, s.get_status_text(),
                       s.i_x, s.i_y, i_dest_x, i_dest_y, s_dest_name,
                       s.i_travelling_speed, s.i_turns_left))
        print(
            "+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+"
        )
        print

        sp_txt = Data_CONST.get_text_list('SHIP_SPECIALS')

        for i, s in self.d_ships.items():
            d_design = s.d_design
            print("    === ship_id # %i ===" % i)
            for i_dev_id in d_design['special_devices']:
                txt = sp_txt[i_dev_id] if (
                    i_dev_id < sp_txt.__len__()) else '<out-of-range>'
                print("        special device: %2i ... %s" % (i_dev_id, txt))
            print
    def draw(self):
        PLAYERS = self.list_players()
        PLANETS = self.list_planets()
        star = self.o_star
        planet = self.o_planet
        colony = self.o_colony
        colony_id = colony.i_id

        self.blit(self.get_image('background', 'starfield'), (0, 0))
        self.blit(
            self.get_planet_background(planet.i_terrain, planet.i_picture),
            (0, 0))
        self.blit(self.get_image('colony_screen', 'panel'), (0, 0))

        self.reset_triggers_list()
        self.add_trigger({
            'action': "screen",
            'screen': "colony_production",
            'colony_id': colony_id,
            'rect': pygame.Rect((519, 123), (61, 22))
        })

        ICON_AND_Y_OFFSET = {
            K_FARMER: (1, 62),
            K_WORKER: (3, 92),
            K_SCIENTIST: (5, 122)
        }

        for i in range(K_MAX_STAR_OBJECTS):
            object_id = star.v_object_ids[i]
            if object_id != 0xFFFF:
                object = PLANETS[object_id]
                print "type: %i" % object.i_type

                if object.is_asteroid_belt():
                    x = 6
                    y = 22 + (24 * i)
                    self.blit(
                        self.get_image('colony_screen', 'asteroids_scheme'),
                        (x, y))
                    self.write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, x + 29,
                                    y + 9, "Asteroids")

                if object.is_gas_giant():
                    x = 11
                    y = 27 + (24 * i)
                    self.blit(
                        self.get_image('colony_screen', 'gasgiant_scheme'),
                        (x, y))
                    write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, x + 24, y + 4,
                               "Gas Giant -")
                    write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, x + 24, y + 15,
                               "uninhabitable")

                elif object.is_planet():
                    terrain = object.i_terrain
                    size = object.i_size
                    x = 10 + [6, 4, 3, 1, 0][size]
                    y = 26 + (24 * i) + [6, 4, 2, 1, 0][size]
                    self.blit(self.get_image('planet_scheme', terrain, size),
                              (x, y))

            self.blit(self.get_image('colony_screen', 'scheme_arrow'),
                      (6, 31 + (24 * i)))

        title_text = "%s of %s" % (Data_CONST.get_text_list(
            'COLONY_ASSIGNMENT')[colony.i_assignment], colony.s_name)
        title_surface = self.render(K_FONT5, K_PALETTE_TITLE, title_text, 2)
        (tw, th) = title_surface.get_size()

        self.blit(title_surface, (320 - (tw / 2), 1))

        #    total_population = (1000 * colony['population']) + colony['pop_raised']
        #    print
        #    print "    Colony:     %s" % colony.name
        #    print "    Population: %i (+%i)" % (total_population, colony['pop_grow'])
        #    print "    Industry:   %i" % colony.industry()
        #    print "    Research:   %i" % colony.research()
        #    print "    Food (result):%i (%i)" % (colony.food(), colony.food() - colony.population)
        #    print "    Colonists:"

        player_government_id = PLAYERS[colony.i_owner_id].get_racepick_item(
            'goverment')

        self.blit(self.get_image('government', 'icon', player_government_id),
                  (310, 32))

        # TODO: implement negative morale
        self.repeat_draw(340, 35, self.get_image('morale_icon', 'good'),
                         colony.i_morale // 10, 30, 7, 155)

        x = 10 + self.repeat_draw(128, 64, self.get_image('production_10food'),
                                  colony.i_food // 10, 20, 6, 98)
        self.repeat_draw(x, 64, self.get_image('production_1food'),
                         colony.i_food % 10, 20, 6, 98)

        # industry icons
        number = (colony.i_industry // 10) + (colony.i_industry % 10)
        xx = min(int(round(160 / max(1, number))), 20)
        x = self.repeat_draw(128, 94, self.get_image('production_10industry'),
                             colony.i_industry // 10, xx, 99, 162)
        self.repeat_draw(x, 94, self.get_image('production_1industry'),
                         colony.i_industry % 10, xx, 99, 162)

        # research icons
        number = (colony.i_research // 10) + (colony.i_research % 10)
        xx = min(int(round(160 / max(1, number))), 20)
        #print "### colony_screen::draw ... research icons ... number = %i, xx = %i" % (number, xx)
        x = self.repeat_draw(128, 124, self.get_image('production_10research'),
                             colony.i_research // 10, xx, 99, 162)
        self.repeat_draw(x, 124, self.get_image('production_1research'),
                         colony.i_research % 10, xx, 99, 162)

        for t in (K_FARMER, K_WORKER, K_SCIENTIST):
            c = len(colony.d_colonists[t])
            xx = 30 if c < 7 else 190 / c
            icon, y = ICON_AND_Y_OFFSET[t]

            for i in range(c):
                colonist = colony.d_colonists[t][i]
                race = colonist['race']
                picture = PLAYERS[race].i_picture
                x = 310 + xx * i
                self.blit(self.get_image('race_icon', picture, icon), (x, y))
                if i == (c - 1):
                    xx = 28  # enlarge the Rect of last icon (no other icon is drawn over it...)
                self.add_trigger({
                    'action':
                    "pick-colonist:%.2x:%i" % (t, (c - i)),
                    'rect':
                    pygame.Rect((x, y), (xx, 28))
                })

        x = 0
        for i in range(colony.i_num_marines):
            self.blit_image((x, 450), 'race_icon', picture, 0x07)
            x += 30

        # TODO: count in all races not just owner!
        total_population = (1000 * colony.total_population()) + sum(
            colony.v_pop_raised)
        pop_text = "Pop %i,%.3i k (+%i)" % (
            (total_population // 1000),
            (total_population % 1000), sum(colony.v_pop_grow))
        population = self.render(K_FONT3, K_PALETTE_POPULATION, pop_text, 2)
        (tw, th) = population.get_size()

        self.blit(population, (529, 3))
    def draw(self):
        PLAYERS    = self.list_players()
        PLANETS    = self.list_planets()
        star       = self.o_star
        planet     = self.o_planet
        colony     = self.o_colony
        colony_id  = colony.i_id

        self.blit(self.get_image('background', 'starfield'), (0, 0))
        self.blit(self.get_planet_background(planet.i_terrain, planet.i_picture), (0, 0))
        self.blit(self.get_image('colony_screen', 'panel'), (0, 0))

        self.reset_triggers_list()
        self.add_trigger({'action': "screen", 'screen': "colony_production", 'colony_id': colony_id, 'rect': pygame.Rect((519, 123), ( 61, 22))})

        ICON_AND_Y_OFFSET = { K_FARMER: (1,62), K_WORKER: (3,92), K_SCIENTIST: (5,122) }

        for i in range(K_MAX_STAR_OBJECTS):
            object_id = star.v_object_ids[i]
            if object_id != 0xFFFF:
                object = PLANETS[object_id]
                print "type: %i" % object.i_type

                if object.is_asteroid_belt():
                    x = 6
                    y = 22 + (24 * i)
                    self.blit(self.get_image('colony_screen', 'asteroids_scheme'), (x, y))
                    self.write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, x + 29, y + 9, "Asteroids")

                if object.is_gas_giant():
                    x = 11
                    y = 27 + (24 * i)
                    self.blit(self.get_image('colony_screen', 'gasgiant_scheme'), (x, y))
                    write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, x + 24, y + 4,  "Gas Giant -")
                    write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, x + 24, y + 15, "uninhabitable")

                elif object.is_planet():
                    terrain = object.i_terrain
                    size = object.i_size
                    x = 10 + [6, 4, 3, 1, 0][size]
                    y = 26 + (24 * i) + [6, 4, 2, 1, 0][size]
                    self.blit(self.get_image('planet_scheme', terrain, size), (x, y))

            self.blit(self.get_image('colony_screen', 'scheme_arrow'), (6,  31 + (24 * i)))

        title_text    = "%s of %s" % (Data_CONST.get_text_list('COLONY_ASSIGNMENT')[colony.i_assignment], colony.s_name)
        title_surface = self.render(K_FONT5, K_PALETTE_TITLE, title_text, 2)
        (tw, th)      = title_surface.get_size()

        self.blit(title_surface, (320 - (tw / 2), 1))

    #    total_population = (1000 * colony['population']) + colony['pop_raised']
    #    print
    #    print "    Colony:     %s" % colony.name
    #    print "    Population: %i (+%i)" % (total_population, colony['pop_grow'])
    #    print "    Industry:   %i" % colony.industry()
    #    print "    Research:   %i" % colony.research()
    #    print "    Food (result):%i (%i)" % (colony.food(), colony.food() - colony.population)
    #    print "    Colonists:"

        player_government_id = PLAYERS[colony.i_owner_id].get_racepick_item('goverment')

        self.blit(self.get_image('government', 'icon', player_government_id), (310, 32))

        # TODO: implement negative morale
        self.repeat_draw(340, 35, self.get_image('morale_icon', 'good'), colony.i_morale // 10, 30, 7, 155)

        x = 10 + self.repeat_draw(128, 64, self.get_image('production_10food'), colony.i_food // 10, 20, 6, 98)
        self.repeat_draw(x, 64, self.get_image('production_1food'), colony.i_food % 10, 20, 6, 98)

        # industry icons
        number = (colony.i_industry // 10) + (colony.i_industry % 10)
        xx = min(int(round(160 / max(1, number))), 20)
        x = self.repeat_draw(128, 94, self.get_image('production_10industry'), colony.i_industry // 10, xx, 99, 162)
        self.repeat_draw(x, 94, self.get_image('production_1industry'), colony.i_industry % 10, xx, 99, 162)

        # research icons
        number = (colony.i_research // 10) + (colony.i_research % 10)
        xx = min(int(round(160 / max(1, number))), 20)
        #print "### colony_screen::draw ... research icons ... number = %i, xx = %i" % (number, xx)
        x = self.repeat_draw(128, 124,self.get_image('production_10research'), colony.i_research // 10, xx, 99, 162)
        self.repeat_draw(x, 124, self.get_image('production_1research'), colony.i_research % 10, xx, 99, 162)

        for t in (K_FARMER, K_WORKER, K_SCIENTIST):
            c = len(colony.d_colonists[t])
            xx = 30 if c < 7 else 190/c
            icon, y = ICON_AND_Y_OFFSET[t]

            for i in range(c):
                colonist = colony.d_colonists[t][i]
                race     = colonist['race']
                picture  = PLAYERS[race].i_picture
                x = 310 + xx * i
                self.blit(self.get_image('race_icon', picture, icon), (x, y))
                if i == (c - 1):
                    xx = 28 # enlarge the Rect of last icon (no other icon is drawn over it...)
                self.add_trigger({'action': "pick-colonist:%.2x:%i" % (t, (c - i)), 'rect': pygame.Rect((x, y), (xx, 28))})

        x = 0
        for i in range(colony.i_num_marines):
            self.blit_image((x, 450), 'race_icon', picture, 0x07)
            x += 30

        # TODO: count in all races not just owner!
        total_population   = (1000 * colony.total_population()) + sum(colony.v_pop_raised)
        pop_text           = "Pop %i,%.3i k (+%i)" % ((total_population // 1000), (total_population % 1000), sum(colony.v_pop_grow))
        population         = self.render(K_FONT3, K_PALETTE_POPULATION, pop_text, 2)
        (tw, th)           = population.get_size()

        self.blit(population, (529, 3))
    def draw(self):
        PLAYERS    = self.list_players()
        PLANETS    = self.list_planets()
        star       = self.o_star
        planet     = self.o_planet
        colony     = self.o_colony
        colony_id  = colony.i_id
        actual_pop = (1000 * colony.i_population) + sum(colony.v_pop_raised)

        print
        print "    Colony:        %s" % colony.s_name
        print "    Population:    %i (+%i)" % (actual_pop, sum(colony.v_pop_grow))
        print "    Food (result): %i (%i)" % (colony.i_food, colony.i_food - actual_pop)
        print "    Industry:      %i" % colony.i_industry
        print "    Research:      %i" % colony.i_research

        self.reset_triggers_list()
        self.add_trigger({'action': "screen", 'screen': "colony_production", 'colony_id': colony_id, 'rect': pygame.Rect((519, 123), ( 61, 22))})

        # Background and starfield
        self.blit(self.get_image('background', 'starfield'), (0, 0))
        self.blit(self.get_planet_background(planet.i_terrain, planet.i_picture), (0, 0))
        self.blit(self.get_image('colony_screen', 'panel'), (0, 0))

        # Solar system objects list
        for i in range(K_MAX_STAR_OBJECTS):
            self.blit(self.get_image('colony_screen', 'scheme_arrow'), (6,  31 + (24 * i)))
            object_id = star.v_object_ids[i]
            if object_id != 0xFFFF:
                o_object = PLANETS[object_id]

                if o_object.is_asteroid_belt():
                    x = 6
                    y = 22 + (24 * i)
                    self.blit(self.get_image('colony_screen', 'asteroids_scheme'), (x, y))
                    self.write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, 40, y + 5, "Asteroids")

                if o_object.is_gas_giant():
                    x = 11
                    y = 27 + (24 * i)
                    self.blit(self.get_image('colony_screen', 'gasgiant_scheme'), (x, y))
                    self.write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, 40, y + 5,  "Gas Giant")

                elif o_object.is_planet():
                    x = 10 + [6, 4, 3, 1, 0][o_object.i_size]
                    y = 26 + (24 * i) + [6, 4, 2, 1, 0][o_object.i_size]
                    self.blit(self.get_image('planet_scheme', o_object.i_terrain, o_object.i_size), (x, y))
                    self.write_text(K_FONT2, K_PALETTE_SCHEMES_FONT, 40, y + 5,  o_object.s_name)
                    ##JWL: TODO Also need triggers to switch view to this planet if it has a colony

        # Screen title / Population summary
        title_text    = "%s of %s" % (Data_CONST.get_text_list('COLONY_ASSIGNMENT')[colony.i_assignment], colony.s_name)
        title_surface = self.render(K_FONT5, K_PALETTE_TITLE, title_text, 2)
        (tw, th)      = title_surface.get_size()
        self.blit(title_surface, (320 - (tw / 2), 1))

        pop_text           = "Pop %i,%.3i k (%+i k)" % ((actual_pop // 1000), (actual_pop % 1000), sum(colony.v_pop_grow))
        population         = self.render(K_FONT3, K_PALETTE_POPULATION, pop_text, 2)
        (tw, th)           = population.get_size()
        self.blit(population, (520, 3))

        # government/morale icons
        player_government_id = PLAYERS[colony.i_owner_id].get_racepick_item('goverment')
        self.blit(self.get_image('government', 'icon', player_government_id), (310, 32))

        s_morale_type = 'good' if colony.i_morale > 100.0 else 'bad'
        i_morale_num = abs(colony.i_morale - 100.0) // 10
        self.repeat_draw(340, 35, self.get_image('morale_icon', s_morale_type), i_morale_num, 30, 7, 155)

        # Food icons
        #xx = 10
        number = (colony.i_food // 10) + (colony.i_food % 10)
        xx = min(int(round(160 / max(1, number))), 20)
        x  = self.repeat_draw(128, 64, self.get_image('production_10food'), colony.i_food // 10, xx, 99, 162) #6, 98)
        x  = self.repeat_draw(x,   64, self.get_image('production_1food'),  colony.i_food %  10, xx, 99, 162) #6, 98)
        # TODO missing (red outline) food

        # Industry icons
        number = (colony.i_industry // 10) + (colony.i_industry % 10)
        xx = min(int(round(160 / max(1, number))), 20)
        x  = self.repeat_draw(128, 94, self.get_image('production_10industry'), colony.i_industry // 10, xx, 99, 162)
        x  = self.repeat_draw(x,   94, self.get_image('production_1industry'),  colony.i_industry %  10, xx, 99, 162)

        # Research icons
        number = (colony.i_research // 10) + (colony.i_research % 10)
        xx = min(int(round(160 / max(1, number))), 20)
        x  = self.repeat_draw(128, 124, self.get_image('production_10research'), colony.i_research // 10, xx, 99, 162)
        x  = self.repeat_draw(x,   124, self.get_image('production_1research'),  colony.i_research %  10, xx, 99, 162)

        # Colonist icons
        ICON_AND_Y_OFFSET = { K_FARMER: (1,62), K_WORKER: (3,92), K_SCIENTIST: (5,122) }
        for t in (K_FARMER, K_WORKER, K_SCIENTIST):
            c = len(colony.d_colonists[t])
            xx = 30 if c < 7 else 190/c   # Adjust for normal versus overlapped colonist icons
            icon, y = ICON_AND_Y_OFFSET[t]

            for i in range(c):
                colonist = colony.d_colonists[t][i]
                picture  = PLAYERS[colonist.race].i_picture
                x = 310 + xx * i
                self.blit(self.get_image('race_icon', picture, icon), (x, y))
                if i == (c - 1):
                    xx = 28 # enlarge the Rect of last icon (no other icon is drawn over it...)
                self.add_trigger({'action': "pick-colonist:0x%.2x:%i" % (t, i), 'rect': pygame.Rect((x, y), (xx, 28))})

        # Marines / Armors / Mechs
        x = 0
        for i in range(colony.i_num_marines):
            self.blit_image((x, 450), 'race_icon', picture, 0x07)
            x += 30
Beispiel #13
0
 def get_status_text(self):
     return Data_CONST.get_text_list('SHIP_STATUS')[self.i_status]
Beispiel #14
0
 def get_size_text(self):
     return Data_CONST.get_planet_size_text(self.i_size)
Beispiel #15
0
    def draw(self):
        """Draws the background, starsystem dialog window, planets/asteroids orbit schemes, planets picturesand central star picture"""
        star = self.get_star(self.i_star_id)

        X, Y = self.get_normalized_panel_pos((self.i_panel_x, self.i_panel_y))

        self.reset_triggers_list()
        self.add_trigger({
            'action': "ESCAPE",
            'hover_id': "escape_button",
            'rect': pygame.Rect((X + 264, Y + 239), (64, 19))
        })
        self.add_trigger({
            'action': "drag",
            'drag_id': "window_title",
            'rect': pygame.Rect((X + 14, Y + 12), (319, 26))
        })

        self.restore_curr_display_copy()

        # dialog window
        self.blit_image((X, Y), 'starsystem_map', 'panel')

        # dialog title
        title_text = "Star System " + star.s_name
        title_shadow = self.render(K_FONT5, K_PALETTE_TITLE_SHADOW, title_text,
                                   2)
        title = self.render(K_FONT5, K_PALETTE_TITLE, title_text, 2)
        (tw, th) = title.get_size()

        self.blit(title_shadow, (X + 174 - (tw / 2), Y + 20))
        self.blit(title, (X + 173 - (tw / 2), Y + 19))

        if star.visited():
            self.blit_image((X + 156, Y + 120), 'starsystem_map', 'star',
                            star.i_class)

            show_info = None

            for i in range(K_MAX_STAR_OBJECTS):
                planet_id = star.v_object_ids[i]
                if planet_id != 0xffff:
                    planet = self.get_planet(planet_id)

                    # draw a planet/asteroid orbit scheme first
                    if planet.is_asteroid_belt():
                        if i == 0:  # FIXME: where are the asteroid belts for objects 1~4 ?
                            self.blit_image((X + 29, Y + 59), 'starsystem_map',
                                            'asteroids', i)
                    elif planet.is_planet() or planet.is_gas_giant():
                        self.blit_image((X + 29, Y + 59), 'starsystem_map',
                                        'orbit', i)

                    planet_size = planet.i_size
                    x = X + 200 + (25 * i) + (5 - planet_size)
                    y = Y + 121 + (5 - planet_size)
                    hover_id = "planet_%i" % planet_id
                    planet_info = []

                    if planet.is_gas_giant():
                        planet_image = self.get_image('starsystem_map',
                                                      'gas_giant', planet_size)
                        w, h = planet_image.get_size()
                        w -= (10 - planet_size)
                        h -= (10 - planet_size)
                        planet_rect = pygame.Rect((x, y), (w, h))
                        self.blit(planet_image, (x, y))
                        self.add_trigger({
                            'action': "gas_giant",
                            'planet_id': planet_id,
                            'hover_id': hover_id,
                            'rect': planet_rect
                        })
                        planet_info.append("Gas Giant (uninhabitable)")

                    elif planet.is_planet():
                        planet_image = self.get_image('starsystem_map',
                                                      'planet',
                                                      planet.i_terrain,
                                                      planet_size)
                        w, h = planet_image.get_size()
                        w -= (10 - planet_size)
                        h -= (10 - planet_size)
                        planet_rect = pygame.Rect((x, y), (w, h))

                        self.blit(planet_image, (x, y))

                        planet_info.append(
                            "%s %s" %
                            (star.s_name, Data_CONST.get_greek_num_text(i)))
                        planet_info.append("%s, %s" %
                                           (planet.get_size_text(),
                                            planet.get_terrain_text()))

                        colony_id = planet.i_colony_id

                        if colony_id < 0xffff:
                            colony = self.get_colony(colony_id)
                            player = self.get_player(colony.i_owner_id)

                            if colony.is_owned_by(self.get_player_id()
                                                  ) and colony.is_colony():
                                self.add_trigger({
                                    'action': "screen",
                                    'screen': "colony",
                                    'colony_id': colony_id,
                                    'hover_id': hover_id,
                                    'rect': planet_rect
                                })
                                planet_info.append("%i / %i pop" %
                                                   (colony.i_population,
                                                    colony.i_max_population))
                            else:
                                self.add_trigger({
                                    'action': "enemy_colony",
                                    'hover_id': hover_id,
                                    'rect': planet_rect
                                })
                                planet_info.append("??? enemy pop")

                            subkey = 'outpost_mark' if colony.is_outpost(
                            ) else 'colony_mark'
                            self.blit_image((x - 6, y), 'starsystem_map',
                                            subkey, player.i_color)

                        else:
                            self.add_trigger({
                                'action': "planet",
                                'planet_id': planet_id,
                                'hover_id': hover_id,
                                'rect': planet_rect
                            })
                            planet_info.append("%i max pop" %
                                               planet.i_max_population)

                        planet_info.append("%s" % (planet.get_minerals_text()))

                    # set the info-box content if hover matches
                    hover = self.get_hover()
                    if hover and hover['hover_id'] == hover_id:
                        show_info = planet_info

            # finally render the on-hover info-box so it's not over-drawed by a planet orbit scheme
            if show_info:
                self.draw_planet_info(show_info)
Beispiel #16
0
 def get_gravity_text(self):
     return Data_CONST.get_planet_gravity_text(self.i_gravity)
Beispiel #17
0
 def get_minerals_text(self):
     return Data_CONST.get_planet_minerals_text(self.i_minerals)
Beispiel #18
0
 def get_size_text(self):
     return Data_CONST.get_planet_size_text(self.i_size)
Beispiel #19
0
 def get_terrain_text(self):
     return Data_CONST.get_planet_terrain_text(self.i_terrain)
    def draw(self):
        """Draws the background, starsystem dialog window, planets/asteroids orbit schemes, planets picturesand central star picture"""
        star  = self.get_star(self.i_star_id)

        X, Y = self.get_normalized_panel_pos((self.i_panel_x, self.i_panel_y))

        self.reset_triggers_list()
        self.add_trigger({'action': "ESCAPE", 'hover_id': "escape_button", 'rect': pygame.Rect((X + 264, Y + 239), (64, 19))})
        self.add_trigger({'action': "drag",   'drag_id': "window_title",   'rect': pygame.Rect((X + 14,  Y + 12),  (319, 26))})

        self.restore_curr_display_copy()

        # dialog window
        self.blit_image((X, Y), 'starsystem_map', 'panel')

        # dialog title
        title_text   = "Star System " + star.s_name
        title_shadow = self.render(K_FONT5, K_PALETTE_TITLE_SHADOW, title_text, 2)
        title        = self.render(K_FONT5, K_PALETTE_TITLE, title_text, 2)
        (tw, th)     = title.get_size()

        self.blit(title_shadow, (X + 174 - (tw / 2), Y + 20))
        self.blit(title,        (X + 173 - (tw / 2), Y + 19))

        if star.visited():
            self.blit_image((X + 156, Y + 120), 'starsystem_map', 'star', star.i_class)

            show_info = None

            for i in range(K_MAX_STAR_OBJECTS):
                planet_id = star.v_object_ids[i]
                if planet_id != 0xffff:
                    planet = self.get_planet(planet_id)

                    # draw a planet/asteroid orbit scheme first
                    if planet.is_asteroid_belt():
                        if i == 0: # FIXME: where are the asteroid belts for objects 1~4 ?
                            self.blit_image((X + 29, Y + 59), 'starsystem_map', 'asteroids', i)
                    elif planet.is_planet() or planet.is_gas_giant():
                        self.blit_image((X + 29, Y + 59), 'starsystem_map', 'orbit', i)

                    planet_size = planet.i_size
                    x           = X + 200 + (25 * i) + (5 - planet_size)
                    y           = Y + 121 + (5 - planet_size)
                    hover_id    = "planet_%i" % planet_id
                    planet_info = []

                    if planet.is_gas_giant():
                        planet_image = self.get_image('starsystem_map', 'gas_giant', planet_size)
                        w, h = planet_image.get_size()
                        w -= (10 - planet_size)
                        h -= (10 - planet_size)
                        planet_rect = pygame.Rect((x, y), (w, h))
                        self.blit(planet_image, (x, y))
                        self.add_trigger({'action': "gas_giant", 'planet_id': planet_id, 'hover_id': hover_id, 'rect': planet_rect})
                        planet_info.append("Gas Giant (uninhabitable)")

                    elif planet.is_planet():
                        planet_image = self.get_image('starsystem_map', 'planet', planet.i_terrain, planet_size)
                        w, h = planet_image.get_size()
                        w -= (10 - planet_size)
                        h -= (10 - planet_size)
                        planet_rect = pygame.Rect((x, y), (w, h))

                        self.blit(planet_image, (x, y))

                        planet_info.append("%s %s" % (star.s_name, Data_CONST.get_greek_num_text(i)))
                        planet_info.append("%s, %s" % (planet.get_size_text(), planet.get_terrain_text()))

                        colony_id = planet.i_colony_id

                        if colony_id < 0xffff:
                            colony = self.get_colony(colony_id)
                            player = self.get_player(colony.i_owner_id)

                            if colony.is_owned_by(self.get_player_id()) and colony.is_colony():
                                self.add_trigger({'action': "screen", 'screen': "colony", 'colony_id': colony_id, 'hover_id': hover_id, 'rect': planet_rect})
                                planet_info.append("%i / %i pop" % (colony.i_population, colony.i_max_population))
                            else:
                                self.add_trigger({'action': "enemy_colony", 'hover_id': hover_id, 'rect': planet_rect})
                                planet_info.append("??? enemy pop")

                            subkey = 'outpost_mark' if colony.is_outpost() else 'colony_mark'
                            self.blit_image((x-6, y), 'starsystem_map', subkey, player.i_color)

                        else:
                            self.add_trigger({'action': "planet", 'planet_id': planet_id, 'hover_id': hover_id, 'rect': planet_rect})
                            planet_info.append("%i max pop" % planet.i_max_population)

                        planet_info.append("%s" % (planet.get_minerals_text()))

                    # set the info-box content if hover matches
                    hover = self.get_hover()
                    if hover and hover['hover_id'] == hover_id:
                        show_info = planet_info

            # finally render the on-hover info-box so it's not over-drawed by a planet orbit scheme
            if show_info:
                self.draw_planet_info(show_info)
Beispiel #21
0
 def get_status_text(self):
     return Data_CONST.get_text_list('SHIP_STATUS')[self.i_status]
Beispiel #22
0
 def get_terrain_text(self):
     return Data_CONST.get_planet_terrain_text(self.i_terrain)
Beispiel #23
0
 def get_gravity_text(self):
     return Data_CONST.get_planet_gravity_text(self.i_gravity)
Beispiel #24
0
 def get_minerals_text(self):
     return Data_CONST.get_planet_minerals_text(self.i_minerals)