Beispiel #1
0
 def choose_server_ip_in_a_list(self):
     servers_list = None
     try:
         f = urllib.urlopen(SERVERS_LIST_URL)
         if f.read(len(SERVERS_LIST_HEADER)) == SERVERS_LIST_HEADER:
             servers_list = f.readlines()
     except:
         pass
     if servers_list is None:
         voice.alert([1029]) # hostile sound
         warning("couldn't get the servers list from the metaserver"
                 " => using the default servers list")
         servers_list = DEFAULT_SERVERS
     nb = 0
     menu = Menu()
     for s in servers_list:
         try:
             ip, version, login, port = s.split()[1:]
             # ignore the first parameter (time)
         except:
             warning("line not recognized from the metaserver: %s", s)
             continue
         nb += 1
         if version == compatibility_version():
             menu.append([login, 4073, login], (connect_and_play, ip, port))
     menu.title = nb2msg(len(menu.choices)) + [4078] + nb2msg(nb) + [4079]
     menu.append([4075, 4076], None)
     menu.run()
Beispiel #2
0
 def status(self):
     assert not self.started
     msg = nb2msg(len(self.players)) + [4242] + nb2msg(self.scenario.nb_players_max)
     if len(self.players) >= self.scenario.nb_players_min:
         msg += [4063]
     else:
         msg += [4244] + nb2msg(self.scenario.nb_players_min)
     msg += [9999] + insert_silences([p.login for p in self.players])
     return msg
Beispiel #3
0
 def status(self):
     assert not self.started
     msg = nb2msg(len(self.players)) + [4242] + nb2msg(
         self.scenario.nb_players_max)
     if len(self.players) >= self.scenario.nb_players_min:
         msg += [4063]
     else:
         msg += [4244] + nb2msg(self.scenario.nb_players_min)
     msg += [9999] + insert_silences([p.login for p in self.players])
     return msg
 def _create_game(self, args):
     n, title = args
     Menu([4055] + title,
          [([4103], (self.server.write_line, "create %s 0.5" % n)),
           ([4104], (self.server.write_line, "create %s 1.0" % n)),
           ([4105] + nb2msg(2), (self.server.write_line, "create %s 2.0" % n)),
           ([4105] + nb2msg(4), (self.server.write_line, "create %s 4.0" % n)),
           ([4048], None),
           ],
          default_choice_index=1).run() # XXX not a ServerMenu
 def _create_game(self, args):
     n, title = args
     Menu([4055] + title, [
         ([4103], (self.server.write_line, "create %s 0.5" % n)),
         ([4104], (self.server.write_line, "create %s 1.0" % n)),
         ([4105] + nb2msg(2),
          (self.server.write_line, "create %s 2.0" % n)),
         ([4105] + nb2msg(4),
          (self.server.write_line, "create %s 4.0" % n)),
         ([4048], None),
     ],
          default_choice_index=1).run()  # XXX not a ServerMenu
 def title(self):
     if isinstance(self.model, BuildingSite):
         title = compute_title(self.type.type_name) + compute_title(BuildingSite.type_name)
     else:
         title = self.short_title[:]
     if self.player:
         if self.player == self.interface.player:
             title += nb2msg(self.number)
         elif self.player in self.interface.player.allied:
             title += [4286] + nb2msg(self.player.number) + [self.player.client.login] # "allied 2"
         elif hasattr(self.player, "number") and self.player.number:
             title += [88] + nb2msg(self.player.number) + [self.player.client.login] # "ennemy 2"
         else: # "npc_ai"
             title += [88] # enemy
     return title
 def requirements_msg(self):
     and_index = 0
     msg = []
     for t in self.missing_requirements:
         and_index = len(msg)
         msg += style.get(t, "title")
     if not self.missing_requirements:
         for i, c in enumerate(self.cost):
             if c:
                 and_index = len(msg)
                 msg += nb2msg(c / PRECISION) + style.get("parameters", "resource_%s_title" % i)
         if self.food_cost:
             and_index = len(msg)
             msg += nb2msg(self.food_cost, genre="f") + style.get("parameters", "food_title")
     # add "and" if there are at least 2 requirements
     if and_index > 0:
         msg[and_index:and_index] = style.get("parameters", "and")
     if msg:
         msg[0:0] = style.get("parameters", "requires")
     return msg
Beispiel #8
0
 def title(self):
     if isinstance(self.model, BuildingSite):
         title = compute_title(self.type.type_name) + compute_title(
             BuildingSite.type_name)
     else:
         title = self.short_title[:]
     if self.player:
         if self.player == self.interface.player:
             title += nb2msg(self.number)
         elif self.player in self.interface.player.allied:
             title += [4286] + nb2msg(self.player.number) + [
                 self.player.client.login
             ]  # "allied 2"
         elif hasattr(self.player, "number") and self.player.number:
             title += [88] + nb2msg(self.player.number) + [
                 self.player.client.login
             ]  # "ennemy 2"
         else:  # "npc_ai"
             title += [88]  # enemy
     return title
Beispiel #9
0
def string_to_msg(s, spell=True):
    if not spell:
        return [s]
    l = []
    for c in s:
        if c == ".":
            l.extend([5026])
        elif c in "0123456789":
            l.extend(nb2msg(c))
        else:
            l.extend(c)
    return l
Beispiel #10
0
def string_to_msg(s, spell=True):
    if not spell:
        return [s]
    l = []
    for c in s:
        if c == ".":
            l.extend([5026])
        elif c in "0123456789":
            l.extend(nb2msg(c))
        else:
            l.extend(c)
    return l
Beispiel #11
0
 def requirements_msg(self):
     and_index = 0
     msg = []
     for t in self.missing_requirements:
         and_index = len(msg)
         msg += style.get(t, "title")
     if not self.missing_requirements:
         for i, c in enumerate(self.cost):
             if c:
                 and_index = len(msg)
                 msg += nb2msg(c / PRECISION) + style.get(
                     "parameters", "resource_%s_title" % i)
         if self.food_cost:
             and_index = len(msg)
             msg += nb2msg(self.food_cost, genre="f") + style.get(
                 "parameters", "food_title")
     # add "and" if there are at least 2 requirements
     if and_index > 0:
         msg[and_index:and_index] = style.get("parameters", "and")
     if msg:
         msg[0:0] = style.get("parameters", "requires")
     return msg
Beispiel #12
0
 def title_msg(self, nb=1):
     if self.is_deferred:
         result = style.get("messages", "production_deferred")
     else:
         result = []
     result += self.title
     if self.type is not None:
         t = style.get(self.type.type_name, "title")
         if nb != 1:
             t = nb2msg(nb) + t
         result = substitute_args(result, [t])
     if self.target is not None:
         if self.keyword == "build_phase_two":
             result += style.get(self.target.type.type_name, "title")
         else:
             result += EntityView(self.interface, self.target).title
     return result
 def title_msg(self, nb=1):
     if self.is_deferred:
         result = style.get("messages", "production_deferred")
     else:
         result = []
     result += self.title
     if self.type is not None:
         t = style.get(self.type.type_name, "title")
         if nb != 1:
             t = nb2msg(nb) + t
         result = substitute_args(result, [t])
     if self.target is not None:
         if self.keyword == "build_phase_two":
             result += style.get(self.target.type.type_name, "title")
         else:
             result += EntityView(self.interface, self.target).title
     return result
Beispiel #14
0
 def _load(self):
     s = open(self.path, "U").read()  # "universal newlines"
     # header
     m = re.search("(?m)^title[ \t]+([0-9 ]+)$", s)
     if m:
         l = m.group(1).split(" ")
         l = [int(x) for x in l]
     else:
         l = nb2msg(self.id)
     self.title = l
     # content
     m = re.search("(?m)^sequence[ \t]+([0-9 ]+)$", s)
     if m:
         l = m.group(1).split(" ")
     else:
         l = []
     self.sequence = l
Beispiel #15
0
 def _load(self):
     s = open(self.path, "U").read() # "universal newlines"
     # header
     m = re.search("(?m)^title[ \t]+([0-9 ]+)$", s)
     if m:
         l = m.group(1).split(" ")
         l = [int(x) for x in l]
     else:
         l = nb2msg(self.id)
     self.title = l
     # content
     m = re.search("(?m)^sequence[ \t]+([0-9 ]+)$", s)
     if m:
         l = m.group(1).split(" ")
     else:
         l = []
     self.sequence = l
Beispiel #16
0
 def __init__(self, world, col, row, width):
     self.col = col
     self.row = row
     self.name = "%s%s" % (string.ascii_lowercase[col], row + 1)
     self.id = world.get_next_id()
     self.world = world
     world.squares.append(self)
     world.objects[self.id] = self
     self.place = world
     self.title = [5000 + col] + nb2msg(row + 1)
     self.objects = []
     self.exits = []
     self.xmin = col * width
     self.ymin = row * width
     self.xmax = self.xmin + width
     self.ymax = self.ymin + width
     self.x = (self.xmax + self.xmin) / 2
     self.y = (self.ymax + self.ymin) / 2
Beispiel #17
0
 def __init__(self, world, col, row, width):
     self.col = col
     self.row = row
     self.name = "%s%s" % (string.ascii_lowercase[col], row + 1)
     self.id = world.get_next_id()
     self.world = world
     world.squares.append(self)
     world.objects[self.id] = self
     self.place = world
     self.title = [5000 + col] + nb2msg(row + 1)
     self.objects = []
     self.exits = []
     self.xmin = col * width
     self.ymin = row * width
     self.xmax = self.xmin + width
     self.ymax = self.ymin + width
     self.x = (self.xmax + self.xmin) / 2
     self.y = (self.ymax + self.ymin) / 2
 def description(self):
     d = []
     try:
         if hasattr(self, "qty") and self.qty:
             d += [134] + nb2msg(self.qty) + style.get("parameters", "resource_%s_title" % self.resource_type)
         if hasattr(self, "hp"):
             d += self.hp_status
         if hasattr(self, "mana"):
             d += self.mana_status
         if hasattr(self, "upgrades"):
             d += self.upgrades_status
         if hasattr(self, "is_invisible_or_cloaked") and \
            self.is_invisible_or_cloaked():
             d += [9998, 4289]
         if getattr(self, "is_a_detector", 0):
             d += [9998, 4290]
         if getattr(self, "is_a_cloaker", 0):
             d += [9998, 4291]
     except:
         pass # a warning is given by style.get()
     return d
 def make_menu(self):
     menu = Menu(self.map_title)
     if len(self.registered_players) < self.nb_players_max:
         for p in self.available_players:
             menu.append([4058, p],
                         (self.server.write_line, "invite %s" % p))
         menu.append([4058, 4258], (self.server.write_line, "invite_easy"))
         menu.append([4058, 4257],
                     (self.server.write_line, "invite_aggressive"))
     if len(self.registered_players) >= self.nb_players_min:
         menu.append([4059], (self.server.write_line, "start"))
     for pn, (p, pa, pr) in enumerate(self.registered_players):
         pa = int(pa)
         for a in range(1, len(self.registered_players) + 1):
             if a != pa:
                 menu.append([4284, p, 4285] + nb2msg(a),
                             (self.server.write_line,
                              "move_to_alliance %s %s" % (pn, a)))
         if p in (self.server.login, "ai"):
             self._add_faction_menu(menu, pn, p, pr)
     menu.append([4048, 4060], (self.server.write_line, "cancel_game"))
     return menu
Beispiel #20
0
 def description(self):
     d = []
     try:
         if hasattr(self, "qty") and self.qty:
             d += [134] + nb2msg(self.qty) + style.get(
                 "parameters", "resource_%s_title" % self.resource_type)
         if hasattr(self, "hp"):
             d += self.hp_status
         if hasattr(self, "mana"):
             d += self.mana_status
         if hasattr(self, "upgrades"):
             d += self.upgrades_status
         if hasattr(self, "is_invisible_or_cloaked") and \
            self.is_invisible_or_cloaked():
             d += [9998, 4289]
         if getattr(self, "is_a_detector", 0):
             d += [9998, 4290]
         if getattr(self, "is_a_cloaker", 0):
             d += [9998, 4291]
     except:
         pass  # a warning is given by style.get()
     return d
 def make_menu(self):
     menu = Menu(self.map_title)
     if len(self.registered_players) < self.nb_players_max:
         for p in self.available_players:
             menu.append([4058, p],
                         (self.server.write_line, "invite %s" % p))
         menu.append([4058, 4258], (self.server.write_line, "invite_easy"))
         menu.append([4058, 4257],
                     (self.server.write_line, "invite_aggressive"))
     if len(self.registered_players) >= self.nb_players_min:
         menu.append([4059], (self.server.write_line, "start"))
     for pn, (p, pa, pr) in enumerate(self.registered_players):
         pa = int(pa)
         for a in range(1, len(self.registered_players) + 1):
             if a != pa:
                 menu.append([4284, p, 4285] + nb2msg(a),
                             (self.server.write_line,
                              "move_to_alliance %s %s" % (pn, a)))
         if p in (self.server.login, "ai"):
             self._add_faction_menu(menu, pn, p, pr)
     menu.append([4048, 4060], (self.server.write_line, "cancel_game"))
     return menu
Beispiel #22
0
 def _get_score_msgs(self):
     if self.has_victory:
         victory_or_defeat = [149]
     else:
         victory_or_defeat = [150]
     t = self.world.time / 1000
     m = int(t / 60)
     s = int(t - m * 60)
     msgs = []
     msgs.append(victory_or_defeat + [107] + nb2msg(m) + [65]
                 + nb2msg(s) + [66]) # in ... minutes and ... seconds
     msgs.append(nb2msg(self.nb_units_produced) + [130, 4023, 9998]
                 + nb2msg(self.nb_units_lost) + [146, 9998]
                 + nb2msg(self.nb_units_killed) + [145])
     msgs.append(nb2msg(self.nb_buildings_produced) + [4025, 4022, 9998]
                 + nb2msg(self.nb_buildings_lost) + [146, 9998]
                 + nb2msg(self.nb_buildings_killed) + [145])
     res_msg = []
     for i, _ in enumerate(self.resources):
         res_msg += nb2msg(self.gathered_resources[i] / PRECISION) \
                    + style.get("parameters", "resource_%s_title" % i) \
                    + [4256, 9998] \
                    + nb2msg(self.consumed_resources()[i] / PRECISION) \
                    + [4024, 9999]
     msgs.append(res_msg[:-1])
     msgs.append([4026] + nb2msg(self._get_score()) + [2008])
     return msgs
Beispiel #23
0
 def get_status_msg(self):
     return [4018] + self.scenario.title + [9999]\
            + insert_silences([p.login for p in self.human_players]) + [9999]\
            + nb2msg(self.get_nb_minutes()) + [65]
Beispiel #24
0
def modify_volume(incr):
    set_volume(min(1, max(0, get_volume() + .1 * incr)))
    sound_stop()
    voice.item(nb2msg(round(get_volume() * 100)) + [4253])
Beispiel #25
0
 def hp_status(self):
     return nb2msg(self.hp) + [39] + nb2msg(self.hp_max)
Beispiel #26
0
 def mana_status(self):
     if self.mana_max > 0:
         return nb2msg(self.mana) + [4247] + nb2msg(self.mana_max)
     else:
         return []
Beispiel #27
0
 def _countdown(self):
     voice.important([4062])  # "the game starts in 5 seconds"
     for n in [5, 4, 3, 2, 1, 0]:
         voice.item(nb2msg(n))
         time.sleep(1)
     pygame.event.clear(KEYDOWN)
 def mana_status(self):
     if self.mana_max > 0:
         return nb2msg(self.mana) + [4247] + nb2msg(self.mana_max)
     else:
         return []
Beispiel #29
0
 def move_to_alliance(self, player_index, alliance):
     player = self.players[int(player_index)]
     player.alliance = int(alliance)
     self.broadcast([4284, player.login, 4285] + nb2msg(player.alliance))
Beispiel #30
0
 def move_to_alliance(self, player_index, alliance):
     player = self.players[int(player_index)]
     player.alliance = int(alliance)
     self.broadcast([4284, player.login, 4285] + nb2msg(player.alliance))
Beispiel #31
0
 def get_status_msg(self):
     return [4018] + self.scenario.title + [9999]\
            + insert_silences([p.login for p in self.human_players]) + [9999]\
            + nb2msg(self.get_nb_minutes()) + [65]
Beispiel #32
0
 def _countdown(self):
     voice.important([4062]) # "the game starts in 5 seconds"
     for n in [5, 4, 3, 2, 1, 0]:
         voice.item(nb2msg(n))
         time.sleep(1)
     pygame.event.clear(KEYDOWN)
Beispiel #33
0
def modify_volume(incr):
    set_volume(min(1, max(0, get_volume() + .1 * incr)))
    sound_stop()
    voice.item(nb2msg(round(get_volume() * 100)) + [4253])
 def hp_status(self):
     return nb2msg(self.hp) + [39] + nb2msg(self.hp_max)