Ejemplo n.º 1
0
 def slot__showMapOverlayWindow(self):
     w = self.mapOverlayWindow()
     signaller.connect(w, "signal__change",
                       lambda overlay: self.slot__setMapOverlay(overlay))
     w.create()
     self.active_window = w
     return
Ejemplo n.º 2
0
 def ask_company_name(self,give_warning=False):
     pygame.draw.rect(self.window, (212,212,212), self.gui_rect)
     title = global_variables.standard_font.render("Name of company:",True,(0,0,0))
     self.window.blit(title, (self.gui_rect[0] + 10, self.gui_rect[1] + 10))
     self.text_receiver = entry.entry(self.window, 
                          (self.gui_rect[0] + 10, self.gui_rect[1] + 45), 
                          self.gui_rect[2] - 20, 
                          global_variables.max_letters_in_company_names)
     self.buttons = {}
     self.buttons["ok"] = button.button(
         "ok", 
         self.window, 
         topleft = (self.gui_rect[0] + self.gui_rect[2] - 100,self.gui_rect[1] + self.gui_rect[3] - 40), 
         fixed_size = None)
     signaller.connect(self.buttons["ok"],"signal__clicked",self.ask_company_capital)
     self.buttons["cancel"] = button.button(
         "cancel", 
         self.window, 
         topleft = (self.gui_rect[0] + self.gui_rect[2] - 65,self.gui_rect[1] + self.gui_rect[3] - 40), 
         fixed_size = None)
     signaller.connect(self.buttons["cancel"],"signal__clicked",self.create_intro_gui);
     if give_warning:
         warning_label = global_variables.standard_font_small.render("No double space, no blanks",True,(0,0,0))
         self.window.blit(warning_label, (self.gui_rect[0] + 10, self.gui_rect[1] + 90))
         pygame.display.flip()
Ejemplo n.º 3
0
 def merchant_pick_name(self, resource, give_length_warning=False):
     """
     Function to get the name of the merchant
     give_length_warning         If true, this will specify the max text size as part of the title.
     """
     self.menu_position = "pick name"
     self.selections["resource"] = resource
     #check that this does not already exist
     exists = False
     for firm_instance in self.solar_system_object_link.current_player.owned_firms.values(
     ):
         if isinstance(firm_instance, company.merchant):
             if firm_instance.from_location == self.selections[
                     "from_location"]:
                 if firm_instance.to_location == self.selections[
                         "to_location"]:
                     if firm_instance.resource == resource:
                         exists = True
     if exists:
         print_dict = {
             "text":
             "A merchant from " +
             str(self.selections["from_location"].name) + " to " +
             str(self.selections["to_location"].name) + " trading " +
             str(resource) + " does already exist",
             "type":
             "general gameplay info"
         }
         self.solar_system_object_link.messages.append(print_dict)
     else:
         pygame.draw.rect(self.action_surface, (212, 212, 212), self.rect)
         pygame.draw.rect(self.action_surface, (0, 0, 0), self.rect, 2)
         pygame.draw.line(self.action_surface, (255, 255, 255),
                          (self.rect[0], self.rect[1]),
                          (self.rect[0] + self.rect[2], self.rect[1]))
         pygame.draw.line(self.action_surface, (255, 255, 255),
                          (self.rect[0], self.rect[1]),
                          (self.rect[0], self.rect[1] + self.rect[3]))
         text = global_variables.standard_font.render(
             "Choose name for merchant:", True, (0, 0, 0))
         self.action_surface.blit(text,
                                  (self.rect[0] + 10, self.rect[1] + 10))
         if give_length_warning:
             warning = global_variables.standard_font.render(
                 "Name must be unique", True, (0, 0, 0))
             self.action_surface.blit(
                 warning, (self.rect[0] + 10, self.rect[1] + 50))
         self.text_receiver = entry.entry(
             self.action_surface,
             topleft=(self.rect[0] + 10, self.rect[1] + 90),
             width=self.rect[3] - 20,
             max_letters=global_variables.max_letters_in_company_names)
         self.text_receiver.active = True
         self.ok_button = button.button("ok",
                                        self.action_surface,
                                        fixed_size=(100, 35),
                                        topleft=(self.rect[0] + 10,
                                                 self.rect[1] + 150))
         signaller.connect(self.ok_button, "signal__clicked",
                           self.merchant_build)
Ejemplo n.º 4
0
    def create(self):
        """
        The creation function.  
        """
        pygame.draw.rect(self.action_surface, (212, 212, 212), self.rect)
        pygame.draw.rect(self.action_surface, (0, 0, 0), self.rect, 2)
        pygame.draw.line(self.action_surface, (255, 255, 255),
                         (self.rect[0], self.rect[1]),
                         (self.rect[0] + self.rect[2], self.rect[1]))
        pygame.draw.line(self.action_surface, (255, 255, 255),
                         (self.rect[0], self.rect[1]),
                         (self.rect[0], self.rect[1] + self.rect[3]))

        self.button_labels = [
            "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus",
            "neptune"
        ]

        self.buttons = {}
        for i, button_label in enumerate(self.button_labels):
            b = button.button(button_label,
                              self.action_surface,
                              topleft=(self.rect[0] + 5,
                                       self.rect[1] + 5 + i * 30),
                              fixed_size=(self.rect[2] - 10, 25))
            self.buttons[button_label] = b
            signaller.connect(b, "signal__clicked",
                              lambda: self.planet_jump(b.label()))
Ejemplo n.º 5
0
 def draw_submenu_button(self,button_name,parameter,size,pos):
     b = button.button(
         button_name,
         self.action_surface,
         fixed_size=size,
         topleft=pos
         )
     signaller.connect(b,"signal__clicked",lambda: self.go_to_submenu(parameter))
     return b
Ejemplo n.º 6
0
 def draw_subfunction_button(self,button_name,slot,size,pos):
     b = button.button(
         button_name,
         self.action_surface,
         fixed_size=size,
         topleft=pos
         )
     signaller.connect(b,"signal__clicked",slot)
     return b
Ejemplo n.º 7
0
 def execute(label, technology):
     """
     This function is activated on scrollbar value change on the size selection box, and updates the input_
     output_dict
     """
     update_rect = pygame.Rect(self.rect[0] + 50, self.rect[1] + 170,
                               self.rect[2] - 100, self.rect[3] - 250)
     pygame.draw.rect(self.action_surface, (212, 212, 212), update_rect)
     size_info = global_variables.standard_font_small.render(
         "size: " + str(self.slider.position), True, (0, 0, 0))
     self.action_surface.blit(size_info,
                              (self.rect[0] + 130, self.rect[1] + 170))
     lineno = 0
     for put in ["input", "output"]:
         lineno = lineno + 1
         direction_info = global_variables.standard_font_small.render(
             put + ":", True, (0, 0, 0))
         self.action_surface.blit(
             direction_info,
             (self.rect[0] + 130, self.rect[1] + 170 + lineno * 20))
         #                print technology.keys()
         for resource in technology["input_output_dict"][put].keys():
             lineno = lineno + 1
             if resource in self.solar_system_object_link.mineral_resources + [
                     "food"
             ] and put == "output":
                 mining_opportunity = self.solar_system_object_link.current_planet.current_base.get_mining_opportunities(
                     self.solar_system_object_link.current_planet,
                     resource)
                 unmodified_output = technology["input_output_dict"][
                     "output"][resource]
                 value = (mining_opportunity / 10) * unmodified_output
                 value = int(value * self.slider.position)
                 value_info = global_variables.standard_font_small.render(
                     resource + ": " + str(value) +
                     " (location modifier: " +
                     str(round(mining_opportunity, 2)) + ")", True,
                     (0, 0, 0))
             else:
                 value = technology["input_output_dict"][put][resource]
                 value = value * self.slider.position
                 value_info = global_variables.standard_font_small.render(
                     resource + ": " + str(value), True, (0, 0, 0))
             self.action_surface.blit(
                 value_info,
                 (self.rect[0] + 150, self.rect[1] + 170 + lineno * 20))
     self.ok_button = button.button(
         "ok",
         self.action_surface,
         fixed_size=(100, 35),
         topleft=(self.rect[0] + self.rect[2] - 110,
                  self.rect[1] + self.rect[3] - 40))
     signaller.connect(self.ok_button, "signal__clicked",
                       lambda: self.commodity_build_firm(existing_firm))
     pygame.display.flip()
Ejemplo n.º 8
0
 def createBaseSubcommandbox(self):
     self.buttonlinks = [
         "base_population_info", "base_list_of_companies",
         "base_list_of_firms", "base_and_firm_market_window",
         "base_build_menu"
     ]
     self.buttonnicenames = [
         "population", "companies", "firms", "market", "build"
     ]
     i = 0
     b = button.button("population",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["population"] = b
     signaller.connect(b, "signal__clicked", self.slot__clickBasePopulation)
     i = i + 1
     b = button.button("companies",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["companies"] = b
     signaller.connect(b, "signal__clicked", self.slot__clickBaseCompanies)
     i = i + 1
     b = button.button("firms",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["firms"] = b
     signaller.connect(b, "signal__clicked", self.slot__clickBaseFirms)
     i = i + 1
     b = button.button("market",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["market"] = b
     signaller.connect(b, "signal__clicked", self.slot__clickBaseMarket)
     i = i + 1
     b = button.button("build",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["build"] = b
     signaller.connect(b, "signal__clicked", self.slot__clickBaseBuild)
     return
Ejemplo n.º 9
0
 def ask_company_capital(self,give_warning=False):
     if "country_window" in self.buttons and self.is_country:
         company_name = self.buttons["country_window"].selected
     elif self.text_receiver is not None and not self.is_country:
         company_name = self.text_receiver.text
     else:
         raise Exception("Could not figure out whether country or private company was selected")
     all_ok = True
     if not (0 < len(company_name) <= global_variables.max_letters_in_company_names):
         all_ok = False
     if company_name.find("  ") != -1: #somewhere it is used that there are two double spaces, so we can't allow that in a companyname
         all_ok = False
     if company_name in self.countries and not self.is_country:
         all_ok = False
     if all_ok:
         pygame.draw.rect(self.window, (212,212,212), self.gui_rect)
         title = global_variables.standard_font.render("Starting capital:",True,(0,0,0))
         self.window.blit(title, (self.gui_rect[0] + 10, self.gui_rect[1] + 10))
         self.text_receiver = entry.entry(self.window, 
                              (self.gui_rect[0] + 10, self.gui_rect[1] + 45), 
                              self.gui_rect[2] - 20, 
                              global_variables.max_letters_in_company_names,
                              starting_text = "10000000")
         self.buttons = {}
         self.buttons["ok"] = button.button(
             "ok", 
             self.window, 
             topleft = (self.gui_rect[0] + self.gui_rect[2] - 100,self.gui_rect[1] + self.gui_rect[3] - 40), 
             fixed_size = None)
         signaller.connect(self.buttons["ok"],"signal__clicked",self.start_new_game)
         self.buttons["cancel"] = button.button(
             "cancel", 
             self.window, 
             topleft = (self.gui_rect[0] + self.gui_rect[2] - 65,self.gui_rect[1] + self.gui_rect[3] - 40), 
             fixed_size = None)
         signaller.connect(self.buttons["cancel"],"signal__clicked",self.create_intro_gui);
         self.company_name = company_name
         if give_warning:
             warning_label = global_variables.standard_font_small.render("Starting capital must be an",True,(0,0,0))
             self.window.blit(warning_label, (self.gui_rect[0] + 10, self.gui_rect[1] + 90))
             warning_label2 = global_variables.standard_font_small.render("integer above zero",True,(0,0,0))
             self.window.blit(warning_label2, (self.gui_rect[0] + 10, self.gui_rect[1] + 100))
             pygame.display.flip()
     else:
         self.ask_company_name(give_warning=True)
Ejemplo n.º 10
0
    def ask_country_name(self):
        self.gui_rect = pygame.Rect(global_variables.window_size[0] / 2 - 150,global_variables.window_size[1] / 3 - 50, 300,300)
        pygame.draw.rect(self.window, (212,212,212), self.gui_rect)

        country_window = fast_list.fast_list(self.window, self.countries, rect = pygame.Rect(self.gui_rect[0], self.gui_rect[1], self.gui_rect[2], self.gui_rect[3] - 50))
        self.buttons = {}
        self.buttons["country_window"] = country_window
        self.buttons["ok"] = button.button(
            "ok", 
            self.window, 
            topleft = (self.gui_rect[0] + self.gui_rect[2] - 100,self.gui_rect[1] + self.gui_rect[3] - 40), 
            fixed_size = None)
        signaller.connect(self.buttons["ok"],"signal__clicked",self.ask_company_capital)
        self.buttons["cancel"] = button.button(
            "cancel", 
            self.window, 
            topleft = (self.gui_rect[0] + self.gui_rect[2] - 65,
                       self.gui_rect[1] + self.gui_rect[3] - 40), 
            fixed_size = None)
        signaller.connect(self.buttons["cancel"],"signal__clicked",self.create_intro_gui)
Ejemplo n.º 11
0
 def createFirmSubcommandbox(self):
     self.buttonlinks = [
         "firm_process_info", "base_and_firm_market_window",
         "firm_trade_partners_info"
     ]
     self.buttonnicenames = ["production", "market", "trade partners"]
     i = 0
     b = button.button("production",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["production"] = b
     signaller.connect(b, "signal__clicked", self.slot__clickFirmProduction)
     i = i + 1
     b = button.button("market",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["market"] = b
     signaller.connect(b, "signal__clicked", self.slot__clickFirmMarket)
     i = i + 1
     b = button.button("trade partners",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["trade partners"] = b
     signaller.connect(b, "signal__clicked",
                       self.slot__clickFirmTradePartners)
     return
Ejemplo n.º 12
0
    def create_intro_gui(self):
        self.gui_rect = pygame.Rect(global_variables.window_size[0] / 2 - 90,
                                    global_variables.window_size[1] / 3, 180,180)
        self.text_receiver = None
        pygame.draw.rect(self.window, (212,212,212), self.gui_rect)

        pygame.draw.line(self.window, (255,255,255), (self.gui_rect[0], self.gui_rect[1]), 
                         (self.gui_rect[0] + self.gui_rect[2], self.gui_rect[1]),2)        
        pygame.draw.line(self.window, (255,255,255), (self.gui_rect[0], self.gui_rect[1]), 
                         (self.gui_rect[0], self.gui_rect[1] + self.gui_rect[3]),2)
        button_names= ["New game","Load game","Game settings","Quit game"]
        button_functions = [self.ask_company_type,self.load_callback,self.game_settings_callback,self.quit_callback]
        self.buttons = {}
        for i, button_name in enumerate(button_names):
            topleft=(self.gui_rect[0] + 25,self.gui_rect[1] + i * 35 + 25)
            b=button.button(button_name,
                            self.window,
                            topleft=topleft,
                            fixed_size=(130,30))
            f=button_functions[i]
            signaller.connect(b,"signal__clicked",f)
            self.buttons[i]=b
Ejemplo n.º 13
0
 def create(self):
     """
     The creation function. Doesn't return anything. 
     """
     pygame.draw.rect(self.action_surface, (212, 212, 212), self.rect)
     pygame.draw.rect(self.action_surface, (0, 0, 0), self.rect, 2)
     pygame.draw.line(self.action_surface, (255, 255, 255),
                      (self.rect[0], self.rect[1]),
                      (self.rect[0] + self.rect[2], self.rect[1]))
     pygame.draw.line(self.action_surface, (255, 255, 255),
                      (self.rect[0], self.rect[1]),
                      (self.rect[0], self.rect[1] + self.rect[3]))
     labels = ["visible light", "trade network", "topographical"
               ] + self.solar_system_object_link.mineral_resources
     self.radiobuttons = radiobuttons.radiobuttons(
         labels,
         self.action_surface,
         topleft=(self.rect[0] + 10, self.rect[1] + 10),
         selected=self.solar_system_object_link.current_planet.
         planet_display_mode)
     signaller.connect(self.radiobuttons, "signal__change",
                       self.slot__radioButtonsChanged)
     return
Ejemplo n.º 14
0
    def load_callback(self):
        self.gui_rect = pygame.Rect(global_variables.window_size[0] / 2 - 150,
                                    global_variables.window_size[1] / 3 - 50, 300,300)
        pygame.draw.rect(self.window, (212,212,212), self.gui_rect)
        load_window = fast_list.fast_list(self.window, os.listdir("savegames"), 
                                          rect = pygame.Rect(self.gui_rect[0], 
                                                             self.gui_rect[1], 
                                                             self.gui_rect[2], 
                                                             self.gui_rect[3] - 50))
        self.buttons = {}
        self.buttons["load_window"] = load_window
        self.buttons["ok"] = button.button(
            "ok", 
            self.window, 
            topleft = (self.gui_rect[0] + self.gui_rect[2] - 100,self.gui_rect[1] + self.gui_rect[3] - 40), 
            fixed_size = None)
        signaller.connect(self.buttons["ok"],"signal__clicked",lambda: self.load_game(load_window))

        self.buttons["cancel"] = button.button(
            "cancel", 
            self.window, 
            topleft = (self.gui_rect[0] + self.gui_rect[2] - 65,self.gui_rect[1] + self.gui_rect[3] - 40), 
            fixed_size = None)
        signaller.connect(self.buttons["cancel"],"signal__clicked",self.create_intro_gui)
Ejemplo n.º 15
0
 def ask_company_type(self):
     pygame.draw.rect(self.window, (212,212,212), self.gui_rect)
     title = global_variables.standard_font.render("Type of company:",True,(0,0,0))
     self.window.blit(title, (self.gui_rect[0] + 10, self.gui_rect[1] + 10))
     def dummy_function_for_radiobuttons(label, function_parameter):
         pass
     self.buttons = {}
     self.buttons["type_selector"] = radiobuttons.radiobuttons(
         ["Private company","Country"],
         surface = self.window, 
         topleft = (self.gui_rect[0] + 10, self.gui_rect[1] + 40), 
         selected = None)
     self.buttons["ok"] = button.button(
         "ok", 
         self.window, 
         topleft = (self.gui_rect[0] + self.gui_rect[2] - 100,self.gui_rect[1] + self.gui_rect[3] - 40), 
         fixed_size = None)
     signaller.connect(self.buttons["ok"],"signal__clicked",self.decide_company_type)
     self.buttons["cancel"] = button.button(
         "cancel", 
         self.window, 
         topleft = (self.gui_rect[0] + self.gui_rect[2] - 65,self.gui_rect[1] + self.gui_rect[3] - 40), 
         fixed_size = None)
     signaller.connect(self.buttons["cancel"],"signal__clicked",self.create_intro_gui)
Ejemplo n.º 16
0
 def createCompanySubcommandbox(self):
     self.buttonlinks = [
         "company_ownership_info", "company_financial_info",
         "company_list_of_firms"
     ]
     self.buttonnicenames = [
         "ownership info", "financial info", "owned firms"
     ]
     i = 0
     b = button.button("ownership info",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["ownership_info"] = b
     signaller.connect(b, "signal__clicked",
                       self.slot__clickCompanyOwnershipInfo)
     i = i + 1
     b = button.button("financial info",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["financial info"] = b
     signaller.connect(b, "signal__clicked",
                       self.slot__clickCompanyFinancialInfo)
     i = i + 1
     b = button.button("owned firms",
                       self.subcommand_surface,
                       fixed_size=(self.subcommand_surface.get_width() - 20,
                                   35),
                       topleft=(10, i * 40 + 10))
     self.subcommand_buttons["owned firms"] = b
     signaller.connect(b, "signal__clicked",
                       self.slot__clickCompanyOwnedFirms)
     return
Ejemplo n.º 17
0
 def create_commandbox(self):
     """
     Creates the right-side menu command box
     """
     self.command_surface.fill((150, 150, 150))
     self.command_buttons = {}
     """ Map overlays """
     i = 0
     surface = self.command_surface
     size = (self.command_rect[2] - 20, 35)
     topleft = (10, i * 40 + 10)
     b = button.button("Map overlays",
                       surface,
                       fixed_size=size,
                       topleft=topleft)
     signaller.connect(b, "signal__clicked",
                       lambda: self.slot__showMapOverlayWindow())
     self.command_buttons[b.label()] = b
     """ Planet shortcuts """
     i = i + 1
     topleft = (10, i * 40 + 10)
     b = button.button("Planet shortcuts",
                       surface,
                       fixed_size=size,
                       topleft=topleft)
     signaller.connect(b, "signal__clicked",
                       lambda: self.slot__showPlanetShortcutsWindow())
     self.command_buttons[b.label()] = b
     """ Base overview """
     i = i + 1
     topleft = (10, i * 40 + 10)
     b = button.button("Base overview",
                       surface,
                       fixed_size=size,
                       topleft=topleft)
     signaller.connect(b, "signal__clicked",
                       lambda: self.slot__showBaseOverviewWindow())
     self.command_buttons[b.label()] = b
     """ Technology """
     i = i + 1
     topleft = (10, i * 40 + 10)
     b = button.button("Technology",
                       surface,
                       fixed_size=size,
                       topleft=topleft)
     signaller.connect(b, "signal__clicked",
                       lambda: self.slot__showTechnologyWindow())
     self.command_buttons[b.label()] = b
     """ File menu """
     i = i + 1
     topleft = (10, i * 40 + 10)
     b = button.button("File menu",
                       surface,
                       fixed_size=size,
                       topleft=topleft)
     signaller.connect(b, "signal__clicked",
                       lambda: self.slot__showFileWindow())
     self.command_buttons[b.label()] = b
     """ Trade Menu """
     i = i + 1
     topleft = (10, i * 40 + 10)
     b = button.button("Trade menu",
                       surface,
                       fixed_size=size,
                       topleft=topleft)
     signaller.connect(b, "signal__clicked",
                       lambda: self.slot__showTradeWindow())
     self.command_buttons[b.label()] = b
     """ Company menu """
     i = i + 1
     topleft = (10, i * 40 + 10)
     b = button.button("Company menu",
                       surface,
                       fixed_size=size,
                       topleft=topleft)
     signaller.connect(b, "signal__clicked",
                       lambda: self.slot__showCompanyWindow())
     self.command_buttons[b.label()] = b
Ejemplo n.º 18
0
    def perform_bid(self, chosen_seller_name):
        """
        Function that allows the player to bid on an asset or technology
        """
        if chosen_seller_name not in self.solar_system_object_link.companies.keys(
        ):
            print_dict = {
                "text": str(chosen_seller_name) +
                " was not found - perhaps it was shut down recently.",
                "type": "general gameplay info"
            }
            self.solar_system_object_link.messages.append(print_dict)
#            print "We had an instance of an unknown name: " + str(chosen_seller_name)
        else:
            chosen_seller = self.solar_system_object_link.companies[
                chosen_seller_name]
            current_player = self.solar_system_object_link.current_player

            if self.selections["type"] == "base":
                self.menu_position = "base bidding"
                pygame.draw.rect(self.action_surface, (224, 218, 213),
                                 self.rect)
                pygame.draw.rect(self.action_surface, (0, 0, 0), self.rect, 2)
                pygame.draw.line(self.action_surface, (255, 255, 255),
                                 (self.rect[0], self.rect[1]),
                                 (self.rect[0] + self.rect[2], self.rect[1]))
                pygame.draw.line(self.action_surface, (255, 255, 255),
                                 (self.rect[0], self.rect[1]),
                                 (self.rect[0], self.rect[1] + self.rect[3]))

                instruction = global_variables.standard_font.render(
                    "Enter bid for " + self.selections["bid_on"] + " (pop:" +
                    str(self.selections["sale_object"].population) +
                    ") with deadline " +
                    str(self.selections["sale_object"].for_sale_deadline),
                    True, (0, 0, 0))
                self.action_surface.blit(
                    instruction, (self.rect[0] + 10, self.rect[1] + 10))

                # estimating a value of the base
                potential_base = self.selections["sale_object"]
                if potential_base.is_on_dry_land == "Yes":
                    dry_term = 1
                else:
                    dry_term = 0.01
                mining_values = []
                for resource in potential_base.mining_opportunities:
                    mining_opportunity = potential_base.mining_opportunities[
                        resource]
                    price_of_resource = []
                    for trade_route in potential_base.trade_routes.values():
                        if trade_route["endpoint_links"].index(
                                potential_base) == 1:
                            neighbour = trade_route["endpoint_links"][0]
                        else:
                            neighbour = trade_route["endpoint_links"][1]
                        try:
                            neighbour.market["buy_offers"][resource]
                        except:
                            if self.solar_system_object_link.message_printing[
                                    "debugging"]:
                                print_dict = {
                                    "text":
                                    "DEBUGGING: When calculating bid, we did not find a market in neighbour "
                                    + str(neighbour.name),
                                    "type":
                                    "debugging"
                                }
                                self.solar_system_object_link.messages.append(
                                    print_dict)
                        else:
                            if len(neighbour.market["buy_offers"]
                                   [resource]) > 0:
                                price_of_resource.append(
                                    neighbour.market["buy_offers"][resource][0]
                                    ["price"])
                    if len(price_of_resource) > 0:
                        mean_price_of_resource = sum(price_of_resource) / len(
                            price_of_resource)
                        value = mining_opportunity * mean_price_of_resource
                        mining_values.append(value)
                mining_value_term = sum(mining_values)
                population_term = potential_base.population
                company_term = current_player.company_database[
                    "buy_out_tendency"]
                base_value = int(dry_term * mining_value_term *
                                 population_term * company_term * 0.00000001)

                #start the entry box
                self.text_receiver = entry.entry(
                    self.action_surface,
                    (self.rect[0] + 10, self.rect[1] + 40),
                    300,
                    32,
                    starting_text=str(base_value))

                self.bid_button = button.button("Bid",
                                                self.action_surface,
                                                topleft=(self.rect[0] + 10,
                                                         self.rect[1] + 100))
                signaller.connect(self.bid_button, "signal__clicked",
                                  self.effectuate_base_bid)
                return None

            if current_player.capital > self.selections["price"]:
                if self.selections["type"] in ["technology", "advanced tech."]:
                    self.solar_system_object_link.current_player.known_technologies[
                        self.
                        selections["bid_on"]] = self.selections["sale_object"]
                    current_player.capital = current_player.capital - self.selections[
                        "price"]
                    chosen_seller.capital = chosen_seller.capital + self.selections[
                        "price"]
                    print_dict = {
                        "text":
                        str(self.selections["bid_on"]) + " was bought for " +
                        str(self.selections["price"]) + " from " +
                        str(chosen_seller.name),
                        "type":
                        "general gameplay info"
                    }
                    self.solar_system_object_link.messages.append(print_dict)

                elif self.selections["type"] == "base":
                    print_dict = {
                        "text": "base buying not implemented yet",
                        "type": "general gameplay info"
                    }
                    self.solar_system_object_link.messages.append(print_dict)

                else:
                    raise Exception("Unknown type: " +
                                    str(self.selections["type"]) +
                                    " asked for in the asset sales GUI")

            else:
                print_dict = {
                    "text":
                    current_player.name + " has a capital of " +
                    str(current_player.capital) + " and can't bid " +
                    str(self.selections["price"]),
                    "type":
                    "general gameplay info"
                }
                self.solar_system_object_link.messages.append(print_dict)

        return "clear"
Ejemplo n.º 19
0
    def new_base_ask_for_name(self,
                              sphere_coordinates,
                              give_length_warning=False):
        """
        Function that prompts the user for a name of the new base
        Optional argument give_length_warning includes a label that specifies max " + str(global_variables.max_letters_in_company_names) + " characters
        """

        #first we calculate the distance
        building_base = self.solar_system_object_link.building_base

        if self.solar_system_object_link.current_player != building_base.owner:
            print_dict = {
                "text":
                "Could not transfer population from " +
                str(building_base.name) + " because it is not owned by you.",
                "type":
                "general gameplay info"
            }
            self.solar_system_object_link.messages.append(print_dict)
            pygame.mouse.set_cursor(*pygame.cursors.arrow)
            return

        if sphere_coordinates[0:19] == "transfer population":
            if sphere_coordinates[
                    23:] in self.solar_system_object_link.current_planet.bases.keys(
                    ):
                destination_base = self.solar_system_object_link.current_planet.bases[
                    sphere_coordinates[23:]]
                sphere_coordinates = destination_base.position_coordinate
                if self.solar_system_object_link.current_player != destination_base.owner:
                    print_dict = {
                        "text":
                        "Could not transfer population to " +
                        str(destination_base.name) +
                        " because it is not owned by you.",
                        "type":
                        "general gameplay info"
                    }
                    self.solar_system_object_link.messages.append(print_dict)
                    self.solar_system_object_link.build_base_mode = True
                    pygame.mouse.set_cursor(*pygame.cursors.diamond)
                    return

            else:
                raise Exception(
                    "The destination base " + str(sphere_coordinates[23:]) +
                    "was not found in base dict of " +
                    str(self.solar_system_object_link.current_planet.name))
        else:
            destination_base = None

        if sphere_coordinates == (None, None):  #
            sphere_coordinates = "space base"

        gravitational_constant = 40
        if building_base.home_planet == self.solar_system_object_link.current_planet:  #intraplanetary
            if building_base.terrain_type != "Space" and sphere_coordinates != "space base":  #ground based
                transport_type = "ground transport"
                distance = int(
                    building_base.home_planet.calculate_distance(
                        sphere_coordinates,
                        building_base.position_coordinate)[0]) / 100
            else:  #space based intraplanetary
                if building_base.terrain_type != "Space" and sphere_coordinates == "space base":  #ground to space building - mostly depends on escape velocity
                    transport_type = "space transport"
                    distance = (self.solar_system_object_link.current_planet.
                                gravity_at_surface * gravitational_constant)**2
                else:  #space-to-ground or space-to-space (cheap)
                    transport_type = "space transport"
                    distance = 10.0
        else:  #inter-planetary -- one fixed part and one part ground escape velocity
            transport_type = "space transport"
            distance = 100.0

            #adding an extra for travels between far-away planets
            endpoint_distances = []
            for endpoint in [
                    building_base.home_planet,
                    self.solar_system_object_link.current_planet
            ]:
                while endpoint.planet_data["satellite_of"] != "sun":
                    endpoint = self.solar_system_object_link.planets[
                        endpoint.planet_data["satellite_of"]]
                endpoint_distances.append(
                    endpoint.planet_data["semi_major_axis"])
            distance = distance + int(
                abs(endpoint_distances[0] - endpoint_distances[1])**0.5) / 50

            if building_base.terrain_type != "Space":
                distance = distance + int(
                    (building_base.home_planet.gravity_at_surface *
                     gravitational_constant)**2)
                distance = distance * 2  #because it is generally more difficult to have to launch from surface of planet

#        print "distance is " + str(distance) + " using " + transport_type
        self.pricing = {
            "steel_cost_per_person": 0.51 + distance / 100,
            "power_cost_per_person": 0.5 + distance / 100,
            "transport_cost_per_person": distance,
            "electronics_cost_per_person": 0.01 + distance / 2000,
            "transport_type": transport_type,
            "distance": distance
        }

        pygame.draw.rect(self.action_surface, (212, 212, 212), self.rect)
        pygame.draw.rect(self.action_surface, (0, 0, 0), self.rect, 2)
        pygame.draw.line(self.action_surface, (255, 255, 255),
                         (self.rect[0], self.rect[1]),
                         (self.rect[0] + self.rect[2], self.rect[1]))
        pygame.draw.line(self.action_surface, (255, 255, 255),
                         (self.rect[0], self.rect[1]),
                         (self.rect[0], self.rect[1] + self.rect[3]))

        if destination_base is not None:
            location_description = "Transfering population to " + destination_base.name
        else:
            if sphere_coordinates == "space base":
                location_description = "Building a base in orbit around " + self.solar_system_object_link.current_planet.name
            else:
                location_description = "Building a base at (" + str(
                    round(sphere_coordinates[0])
                ) + "," + str(
                    round(sphere_coordinates[1])
                ) + ") on " + self.solar_system_object_link.current_planet.name

        description = global_variables.standard_font.render(
            location_description, True, (0, 0, 0))
        self.action_surface.blit(description,
                                 (self.rect[0] + 20, self.rect[1] + 20))

        if destination_base is None:
            description = global_variables.standard_font.render(
                "Enter name", True, (0, 0, 0))
            self.action_surface.blit(description,
                                     (self.rect[0] + 20, self.rect[1] + 40))

            if give_length_warning:
                warning = global_variables.standard_font.render(
                    "Name must be unique", True, (0, 0, 0))
                self.action_surface.blit(
                    warning, (self.rect[0] + 20, self.rect[1] + 50))

            self.text_receiver = entry.entry(
                self.action_surface,
                topleft=(self.rect[0] + self.rect[2] / 2 - 100,
                         self.rect[1] + 70),
                width=200,
                max_letters=global_variables.max_letters_in_company_names)
            self.text_receiver.active = True
        else:
            assert self.text_receiver == None

        description = global_variables.standard_font.render(
            "Population to transfer:", True, (0, 0, 0))
        self.action_surface.blit(description,
                                 (self.rect[0] + 20, self.rect[1] + 120))

        price_rect = pygame.Rect(self.rect[0] + 10, self.rect[1] + 210,
                                 self.rect[2] - 20, 80)

        def population_execute(label, price_rect):
            pygame.draw.rect(self.action_surface, (212, 212, 212), price_rect)

            text = primitives.nicefy_numbers(int(
                self.population_bar.position)) + " people"
            rendered_text = global_variables.standard_font.render(
                text, True, (0, 0, 0))
            self.action_surface.blit(rendered_text,
                                     (price_rect[0], price_rect[1]))

            text = primitives.nicefy_numbers(
                int(self.population_bar.position *
                    self.pricing["steel_cost_per_person"])) + " steel"
            rendered_text = global_variables.standard_font.render(
                text, True, (0, 0, 0))
            self.action_surface.blit(rendered_text,
                                     (price_rect[0], price_rect[1] + 15))

            text = primitives.nicefy_numbers(
                int(self.population_bar.position *
                    self.pricing["power_cost_per_person"])) + " power"
            rendered_text = global_variables.standard_font.render(
                text, True, (0, 0, 0))
            self.action_surface.blit(rendered_text,
                                     (price_rect[0], price_rect[1] + 30))

            text = primitives.nicefy_numbers(
                int(self.population_bar.position *
                    self.pricing["transport_cost_per_person"])
            ) + " " + transport_type
            rendered_text = global_variables.standard_font.render(
                text, True, (0, 0, 0))
            self.action_surface.blit(rendered_text,
                                     (price_rect[0], price_rect[1] + 45))

            text = primitives.nicefy_numbers(
                int(self.population_bar.position * self.
                    pricing["electronics_cost_per_person"])) + " electronics"
            rendered_text = global_variables.standard_font.render(
                text, True, (0, 0, 0))
            self.action_surface.blit(rendered_text,
                                     (price_rect[0], price_rect[1] + 60))

            pygame.display.update(price_rect)

        max_size = min(10000, building_base.population)
        min_size = min(max_size / 2, 100)
        self.population_bar = hscrollbar.hscrollbar(
            self.action_surface,
            population_execute, (self.rect[0] + 10, self.rect[1] + 140),
            self.rect[2] - 20, (min_size, max_size),
            start_position=100,
            function_parameter=price_rect)

        description = global_variables.standard_font.render(
            "Price of transfer:", True, (0, 0, 0))
        self.action_surface.blit(description,
                                 (self.rect[0] + 20, self.rect[1] + 170))
        description = global_variables.standard_font.render(
            "Calculated on a cost-distance of " + str(int(distance)), True,
            (0, 0, 0))
        self.action_surface.blit(description,
                                 (self.rect[0] + 20, self.rect[1] + 185))

        population_execute(None, price_rect)

        if destination_base is None:
            self.ok_button = button.button(
                "ok",
                self.action_surface,
                fixed_size=(100, 35),
                topleft=(self.rect[0] + self.rect[2] - 110,
                         self.rect[1] + self.rect[3] - 40))
            signaller.connect(self.ok_button, "signal__clicked",
                              lambda: self.new_base_build(sphere_coordinates))
        else:
            self.ok_button = button.button(
                "ok",
                self.action_surface,
                fixed_size=(100, 35),
                topleft=(self.rect[0] + self.rect[2] - 110,
                         self.rect[1] + self.rect[3] - 40))
            signaller.connect(self.ok_button, "signal__clicked",
                              lambda: self.new_base_build(destination_base))

        self.cancel_button = button.button(
            "cancel",
            self.action_surface,
            fixed_size=(100, 35),
            topleft=(self.rect[0] + self.rect[2] - 220,
                     self.rect[1] + self.rect[3] - 40))
        signaller.connect(self.cancel_button, "signal__clicked", self.exit)