コード例 #1
0
 def footstepnoise(self):
     # assert: "only immobile objects must be taken into account"
     result = style.get(self.type_name, "move")
     if self.airground_type == "ground" and self._terrain_footstep():
         return self._terrain_footstep()
     elif self.airground_type == "ground" and len(self.place.objects) < 30: # save CPU
         d_min = 9999999
         for m in self.place.objects:
             if getattr(m, "speed", 0):
                 continue
             g = style.get(m.type_name, "ground")
             if g and style.has(self.type_name, "move_on_%s" % g[0]):
                 try:
                     k = float(g[1])
                 except IndexError:
                     k = 1.0
                 try:
                     o = self.interface.dobjets[m.id]
                 except KeyError: # probably caused by the world client updates
                     continue
                 try:
                     d = distance(o.x, o.y, self.x, self.y) / k
                 except ZeroDivisionError:
                     continue
                 if d < d_min:
                     result = style.get(self.type_name, "move_on_%s" % g[0])
                     d_min = d
     return result
コード例 #2
0
def order_title(order):
    o = order.split()
    t = style.get(o[0], "title")
    if t is None:
        t = []
        warning("%s.title is None", o[0])
    if len(o) > 1:
        t2 = style.get(o[1], "title")
        if t2 is None:
            warning("%s.title is None", o[1])
        else:
            t = substitute_args(t, [t2])
    return t
コード例 #3
0
 def get_shortcut(self):
     if self.shortcut:
         return unicode(self.shortcut[0])
     if self.type and self.type.type_name:
         s = style.get(self.type.type_name, "shortcut", False)
         if s:
             return unicode(s[0])
コード例 #4
0
ファイル: worldplayerbase.py プロジェクト: ctoth/soundrts
 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
コード例 #5
0
 def _get_score_msgs(self):
     if self.has_victory:
         victory_or_defeat = mp.VICTORY
     else:
         victory_or_defeat = mp.DEFEAT
     t = self.world.time / 1000
     m = int(t / 60)
     s = int(t - m * 60)
     msgs = []
     msgs.append(victory_or_defeat + mp.AT
                 + nb2msg(m) + mp.MINUTES
                 + nb2msg(s) + mp.SECONDS)
     msgs.append(nb2msg(self.nb_units_produced) + mp.UNITS + mp.PRODUCED_F
                 + mp.COMMA
                 + nb2msg(self.nb_units_lost) + mp.LOST
                 + mp.COMMA
                 + nb2msg(self.nb_units_killed) + mp.NEUTRALIZED)
     msgs.append(nb2msg(self.nb_buildings_produced) + mp.BUILDINGS + mp.PRODUCED_M
                 + mp.COMMA
                 + nb2msg(self.nb_buildings_lost) + mp.LOST
                 + mp.COMMA
                 + nb2msg(self.nb_buildings_killed) + mp.NEUTRALIZED)
     res_msg = []
     for i, _ in enumerate(self.resources):
         res_msg += nb2msg(self.gathered_resources[i] / PRECISION) \
                    + style.get("parameters", "resource_%s_title" % i) \
                    + mp.GATHERED + mp.COMMA \
                    + nb2msg(self.consumed_resources()[i] / PRECISION) \
                    + mp.CONSUMED + mp.PERIOD
     msgs.append(res_msg[:-1])
     msgs.append(mp.SCORE + nb2msg(self._get_score())
                 + mp.HISTORY_EXPLANATION)
     return msgs
コード例 #6
0
ファイル: clientservermenu.py プロジェクト: ctoth/soundrts
 def _add_faction_menu(self, menu, pn, p, pr):
     if len(self.map.factions) > 1:
         for r in ["random_faction"] + self.map.factions:
             if r != pr:
                 menu.append([p,] + style.get(r, "title"),
                             (self.server.write_line,
                              "faction %s %s" % (pn, r)))
コード例 #7
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
コード例 #8
0
 def color(self):
     color = style.get(self.type_name, "color", warn_if_not_found=False)
     try:
         return pygame.Color(color[0])
     except:
         try:
             return (255, (int(self.short_title[0]) * int(self.short_title[0])) % 256, int(self.short_title[0]) % 256)
         except:
             return (255, 255, 255)
コード例 #9
0
 def on_wounded(self, attacker_type, attacker_id, level):
     if self.player == self.interface.player:
         self.unit_attacked_alert()
     s = style.get(attacker_type, "attack_hit_level_%s" % level)
     if s is not None:
         if s:
             self.launch_event(random.choice(s))
     else:
         warning("no sound found for: %s %s", attacker_type, "attack_hit_level_%s" % level)
     if get_fullscreen() and attacker_id in self.interface.dobjets:
         self.interface.grid_view.display_attack(attacker_id, self)
コード例 #10
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
コード例 #11
0
 def get_style(self, attr):
     st = style.get(self.type_name, attr)
     if st and st[0] == "if_me":
         if self.player in self.interface.player.allied:
             try:
                 return st[1:st.index("else")]
             except ValueError:
                 return st[1:]
         else:
             try:
                 return st[st.index("else") + 1:]
             except ValueError:
                 return []
     return st
コード例 #12
0
ファイル: clientgameentity.py プロジェクト: ctoth/soundrts
 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
コード例 #13
0
 def _display(self):
     # map borders
     draw_rect((100, 100 ,100),
               (0, 0,
                self.square_view_width * (self.interface.xcmax + 1),
                self.square_view_height * (self.interface.ycmax + 1)),
               1)
     # backgrounds
     squares_to_view = []
     for xc in range(0, self.interface.xcmax + 1):
         for yc in range(0, self.interface.ycmax + 1):
             sq = self.interface.server.player.world.grid[(xc, yc)]
             color = style.get(sq.type_name, "color", warn_if_not_found=False)
             try:
                 color = pygame.Color(color[0])
             except:
                 color = (0, 25, 0)
             if sq.high_ground:
                 color = (color[0]*2, color[1]*2, color[2]*2)
             if sq in self.interface.server.player.observed_before_squares \
                and sq not in self.interface.server.player.observed_squares:
                 color = (color[0]/10 + 15, color[1]/10 + 15, color[2]/10 + 15)
             elif sq not in self.interface.server.player.observed_squares:
                 color = (0, 0, 0)
                 continue
             color = map(lambda x: min(x, 255), color)
             draw_rect(color, self._get_rect_from_map_coords(xc, yc))
             squares_to_view.append(sq)
     # walls
     for sq in squares_to_view:
         exits = set([e.o for e in sq.exits if not e.is_blocked()])
         walls = set([-90, 90, 180, 0]) - exits
         x, y = self._xy_coords(sq.x, sq.y)
         for color, borders in (((100, 100, 100), walls), ((0, 0, 0), exits)):
             for o in borders:
                 dx = cos(radians(o)) * self.square_view_width / 2
                 dy = - sin(radians(o)) * self.square_view_width / 2
                 draw_line(color,
                           (x - dx - dy, y - dy - dx),
                           (x - dx + dy, y - dy + dx))
コード例 #14
0
 def description(self):
     d = []
     try:
         if hasattr(self, "qty") and self.qty:
             d += mp.CONTAINS + 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 getattr(self, "is_invisible", 0) or getattr(self, "is_cloaked", 0):
             d += mp.COMMA + mp.INVISIBLE
         if getattr(self, "is_a_detector", 0):
             d += mp.COMMA + mp.DETECTOR
         if getattr(self, "is_a_cloaker", 0):
             d += mp.COMMA + mp.CLOAKER
     except:
         pass # a warning is given by style.get()
     return d
コード例 #15
0
 def when_moving_through(self):
     return style.get(self.model.type_name, "when_moving_through")
コード例 #16
0
 def on_production_deferred(self):
     voice.info(style.get("messages", "production_deferred"))
コード例 #17
0
 def on_order_impossible(self, reason=None):
     if self.player is not self.interface.player: return
     self.launch_event_style("order_impossible", alert=True)
     if reason is not None:
         voice.info(style.get("messages", reason))
コード例 #18
0
 def on_use_complete(self, ability):
     st = style.get(ability, "alert")
     if not st:
         return
     s = random.choice(st)
     self.launch_alert(s)
コード例 #19
0
 def _terrain_footstep(self):
     t = self.place.type_name
     if t:
         g = style.get(t, "ground")
         if g and style.has(self.type_name, "move_on_%s" % g[0]):
             return style.get(self.type_name, "move_on_%s" % g[0])
コード例 #20
0
def _ord_index(keyword):
    try:
        return float(style.get(keyword, "index")[0])
    except:
        warning("%s.index should be a number (check style.txt)", keyword)
        return 9999  # end of the list
コード例 #21
0
def compute_title(type_name):
    t = style.get(type_name, "title")
    if t is None:
        return []
    else:
        return [int(x) for x in t]
コード例 #22
0
def compute_title(type_name):
    t = style.get(type_name, "title")
    if t is None:
        return []
    else:
        return [int(x) for x in t]
コード例 #23
0
 def upgrades_status(self):
     result = []
     for u in self.upgrades:
         result += style.get(u, "title")
     return result
コード例 #24
0
ファイル: clientmain.py プロジェクト: MatejGolian/soundrts
 def _add_faction_menus(self, menu):
     for pn, (p, pr) in enumerate(zip(self._players, self._factions)):
         for r in ["random_faction"] + self._map.factions:
             if r != pr:
                 menu.append([p,] + style.get(r, "title"),
                             (self._set_faction, pn, r))
コード例 #25
0
def _ord_index(keyword):
    try:
        return float(style.get(keyword, "index")[0])
    except:
        warning("%s.index should be a number (check style.txt)", keyword)
        return 9999 # end of the list
コード例 #26
0
 def shape(self):
     shape = style.get(self.type_name, "shape", warn_if_not_found=False)
     if shape:
         return shape[0]
コード例 #27
0
 def upgrades_status(self):
     result = []
     for u in self.upgrades:
         result += style.get(u, "title")
     return result
コード例 #28
0
ファイル: clientmain.py プロジェクト: ctoth/soundrts
 def _add_faction_menu(self, menu, pn, p, pr):
     if len(self.map.factions) > 1:
         for r in ["random_faction"] + self.map.factions:
             if r != pr:
                 menu.append([p,] + style.get(r, "title"),
                             (self.set_faction, pn, r))
コード例 #29
0
ファイル: clientmain.py プロジェクト: sanslash332/soundrts
 def _add_race_menu(self, menu, pn, p, pr):
     if len(self.map.races) > 1:
         for r in ["random_race"] + self.map.races:
             if r != pr:
                 menu.append([p,] + style.get(r, "title"),
                             (self.set_race, pn, r))