当前位置: 首页>>代码示例>>Python>>正文


Python maps.Ship类代码示例

本文整理汇总了Python中Core.maps.Ship的典型用法代码示例。如果您正苦于以下问题:Python Ship类的具体用法?Python Ship怎么用?Python Ship使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Ship类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main(url = Config.get("URL", "ships"), debug=False):
    req = urllib2.Request(url)
    req.add_header('User-Agent', useragent)
    stats = urllib2.urlopen(req).read()
    session.execute(Ship.__table__.delete())
    if Config.get("DB", "dbms") == "mysql":
        session.execute(text("ALTER TABLE ships AUTO_INCREMENT=1;", bindparams=[false]))
    else:
        session.execute(text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false]))
    
    for line in sre.findall(stats):
        ship = Ship()
        line = list(line)
        for index, key in enumerate(keys):
            if line[index] in mapping:
                line[index] = mapping[line[index]]
            elif line[index].isdigit():
                line[index] = int(line[index])
            if line[index] not in ('-', '',):
                setattr(ship,key,line[index])
        ship.total_cost = ship.metal + ship.crystal + ship.eonium
        if debug: print "%12s%12s%12s%12s" % (ship.name, ship.class_, ship.race, ship.type,)
        
        session.add(ship)
    
    session.commit()
    session.close()
开发者ID:TBBTNut,项目名称:merlin,代码行数:27,代码来源:shipstats.py

示例2: execute

 def execute(self, message, user, params):
     
     p = Planet.load(*params.group(1,3,5))
     if p is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     ship = Ship.load(name=params.group(6))
     if ship is None:
         message.alert("No Ship called: %s" % (params.group(6),))
         return
     
     scan = p.scan("P")
     if scan is None:
         message.reply("No planet scans available on %s:%s:%s" % (p.x,p.y,p.z,))
         return
     
     planetscan = scan.planetscan
     tick=scan.tick
     res_m=planetscan.res_metal
     res_c=planetscan.res_crystal
     res_e=planetscan.res_eonium
     prod_res=planetscan.prod_res
     rand_id=scan.pa_id
     
     cost_m=ship.metal
     cost_c=ship.crystal
     cost_e=ship.eonium
     total_cost=ship.total_cost
     
     class_factory_table = {'Fighter': 'factory_usage_light', 'Corvette': 'factory_usage_light', 'Frigate': 'factory_usage_medium',
                            'Destroyer': 'factory_usage_medium', 'Cruiser': 'factory_usage_heavy', 'Battleship': 'factory_usage_heavy'}
     prod_modifier_table = {'None': 0.0, 'Low': 0.33, 'Medium': 0.66, 'High': 1.0}
     
     capped_number = min(res_m/cost_m, res_c/cost_c, res_e/cost_e)
     overflow = res_m+res_c+res_e-(capped_number*(cost_m+cost_c+cost_e))
     buildable = capped_number + ((overflow*.95)/total_cost)
     
     reply="Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (p.x,p.y,p.z,rand_id,tick)
     reply+=" can purchase %s: %s"%(ship.name,int(buildable))
     
     for gov in PA.options("govs"):
         bonus = PA.getfloat(gov, "prodcost")
         if bonus == 0:
             continue
         reply+=" | %s: %s"%(PA.get(gov, "name"),int(buildable/(1+bonus)))
     
     factory_usage=getattr(planetscan,class_factory_table[ship.class_])
     if prod_res > 0 and factory_usage != "None":
         max_prod_modifier=prod_modifier_table[factory_usage]
         buildable_from_prod = buildable + max_prod_modifier*prod_res/total_cost
         reply+=" Counting %s res in prod at %s usage:" % (self.num2short(prod_res),factory_usage)
         reply+=" %s"%(int(buildable_from_prod))
         
         for gov in PA.options("govs"):
             bonus = PA.getfloat(gov, "prodcost")
             if bonus == 0:
                 continue
             reply+=" | %s: %s"%(PA.get(gov, "name"),int(buildable_from_prod/(1+bonus)))
     
     message.reply(reply)
开发者ID:Hardware-Hacks,项目名称:merlin,代码行数:60,代码来源:afford.py

示例3: execute

 def execute(self, message, user, params):
     
     search=params.group(1)
     
     Q = session.query(FleetLog)
     
     if search != "":
         ship = Ship.load(name=search)
         if ship is not None:
             Q = Q.filter(FleetLog.ship == ship)
         else:
             u = User.load(search, exact=False, access="member")
             if u is not None:
                 Q = Q.filter(FleetLog.user == u)
             else:
                 Q = Q.filter(FleetLog.id == -1)
     Q = Q.order_by(desc(FleetLog.tick))
     
     result = Q[:10]
     
     if len(result) < 1:
         message.reply("No matches found in the deflog for search '%s'"%(search,))
         return
     
     tick = Updates.current_tick()
     reply = ", ".join(map(lambda x:"%s gave %s %s to %s (%s)"%(x.user.name,self.num2short(x.ship_count),x.ship.name,x.taker.name,x.tick-tick),result))
     message.reply(reply)
开发者ID:Go3Media,项目名称:merlin,代码行数:27,代码来源:logdef.py

示例4: parse_garbage

    def parse_garbage(self, garbage):
        parts = garbage.split()
        ships = {}
        while len(parts) > 1:
            mc = self.countre.match(parts[0])
            ms = self.shipre.match(parts[1])
            if not mc and not ms:
                mc = self.countre.match(parts[1])
                ms = self.shipre.match(parts[0])
            if not mc or not ms:
                break

            count = self.short2num(mc.group(1))
            ship = ms.group(1)

            ship = Ship.load(name=ship)
            if ship is None:
                break

            ships[ship] = count

            parts.pop(0)
            parts.pop(0)
        comment = " ".join(parts)
        return (ships, comment)
开发者ID:TBBTNut,项目名称:merlin,代码行数:25,代码来源:theirdef.py

示例5: execute

 def execute(self, message, user, params):
     
     num, name = params.groups()
     
     ship = Ship.load(name=name)
     if ship is None:
         message.alert("No Ship called: %s" % (name,))
         return
     
     num = self.short2num(num)
     reply="Buying %s %s will cost %s metal, %s crystal and %s eonium."%(num,ship.name,
             self.num2short(ship.metal*num),
             self.num2short(ship.crystal*num),
             self.num2short(ship.eonium*num))
     
     for gov in PA.options("govs"):
         bonus = PA.getfloat(gov, "prodcost")
         if bonus == 0:
             continue
         
         reply += " %s: %s metal, %s crystal and %s eonium."%(
                     PA.get(gov, "name"),
                     self.num2short(ship.metal*(1+bonus)*num),
                     self.num2short(ship.crystal*(1+bonus)*num),
                     self.num2short(ship.eonium*(1+bonus)*num))
     
     reply+=" It will add %s value"%(self.num2short(ship.total_cost*num/100),)
     message.reply(reply)
开发者ID:munin,项目名称:merlin,代码行数:28,代码来源:cost.py

示例6: execute

 def execute(self, message, user, params):
     
     name = params.group(1)
     
     ship = Ship.load(name=name)
     if ship is None:
         message.alert("No Ship called: %s" % (name,))
         return
     message.reply(ship)
开发者ID:JDD,项目名称:DLR,代码行数:9,代码来源:ship.py

示例7: parse_U

    def parse_U(self, scan_id, scan, page):
        for m in re.finditer('(\w+\s?\w*\s?\w*)</td><td[^>]*>(\d+(?:,\d{3})*)</td>', page):
            print m.groups()

            ship = Ship.load(name=m.group(1))
            if ship is None:
                print "No such unit %s" % (m.group(1),)
                continue
            scan.units.append(UnitScan(ship=ship, amount=m.group(2).replace(',', '')))

        session.commit()
开发者ID:munin,项目名称:merlin,代码行数:11,代码来源:parser.py

示例8: drop_ships

 def drop_ships(self, user, taker, ships):
     removed = {}
     tick = Updates.current_tick()
     for name in ships.split():
         ship = Ship.load(name=name)
         if ship is None:
             continue
         for fleet in user.fleets.filter_by(ship=ship):
             removed[fleet.ship.name] = fleet.ship_count
             self.delete_ships(user, taker, fleet, tick)
     session.commit()
     return removed
开发者ID:Go3Media,项目名称:merlin,代码行数:12,代码来源:usedef.py

示例9: execute

    def execute(self, message, user, params):
        
        names = params.group(1).split()
        reply = ""        

        for name in names:
            ship = Ship.load(name=name)
            if ship is None:
                message.alert("No Ship called: %s" % (name,))
                continue
            reply += str(ship) + "\n"
        message.reply(reply[:-1])
开发者ID:JDD,项目名称:merlin,代码行数:12,代码来源:ship.py

示例10: execute

    def execute(self, message, user, params):

        num, name, target = params.groups()
        target = target or "t1"

        ship = Ship.load(name=name)
        num = self.short2num(num)
        if ship is None:
            message.alert("No Ship called: %s" % (name,))
            return
        efficiency = PA.getfloat("teffs", target.lower())
        target_class = getattr(ship, target)
        if ship.damage:
            total_damage = ship.damage * num
        if ship.t1 == "Roids":
            killed = total_damage / 50
            message.reply(
                "%s %s (%s) will capture Asteroid: %s (%s)"
                % (num, ship.name, self.num2short(num * ship.total_cost / 100), killed, self.num2short(killed * 200))
            )
            return
        if ship.t1 == "Struct":
            killed = total_damage / 500
            message.reply(
                "%s %s (%s) will destroy Structure: %s (%s)"
                % (num, ship.name, self.num2short(num * ship.total_cost / 100), killed, self.num2short(killed * 1500))
            )
            return
        targets = session.query(Ship).filter(Ship.class_ == target_class)
        if targets.count() == 0:
            message.reply("%s does not have any targets in that category (%s)" % (ship.name, target))
            return
        reply = "%s %s (%s) hitting %s will " % (
            num,
            ship.name,
            self.num2short(num * ship.total_cost / 100),
            target_class,
        )
        if ship.type.lower() == "norm" or ship.type.lower() == "cloak":
            reply += "destroy "
        elif ship.type.lower() == "emp":
            reply += "hug "
        elif ship.type.lower() == "steal":
            reply += "steal "
        else:
            raise Exception("Erroneous type %s" % (ship.type,))
        for target in targets:
            if ship.type.lower() == "emp":
                killed = int(efficiency * ship.guns * num * float(100 - target.empres) / 100)
            else:
                killed = int(efficiency * total_damage / target.armor)
            reply += "%s: %s (%s) " % (target.name, killed, self.num2short(target.total_cost * killed / 100))
        message.reply(reply)
开发者ID:Go3Media,项目名称:merlin,代码行数:53,代码来源:eff.py

示例11: main

def main(url = Config.get("URL", "ships"), debug=False):
    stats = urllib2.urlopen(url).read()
    session.execute(Ship.__table__.delete())
    session.execute(text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false]))
    
    for line in sre.findall(stats):
        ship = Ship()
        line = list(line)
        for index, key in enumerate(keys):
            if line[index] in mapping:
                line[index] = mapping[line[index]]
            elif line[index].isdigit():
                line[index] = int(line[index])
            if line[index] not in ('-', '',):
                setattr(ship,key,line[index])
        ship.total_cost = ship.metal + ship.crystal + ship.eonium
        if debug: print "%12s%12s%12s%12s" % (ship.name, ship.class_, ship.race, ship.type,)
        
        session.add(ship)
    
    session.commit()
    session.close()
开发者ID:JDD,项目名称:DLR,代码行数:22,代码来源:shipstats.py

示例12: execute

 def execute(self, message, user, params):
     
     p = Planet.load(*params.group(1,3,5))
     if p is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     ship = Ship.load(name=params.group(6))
     if ship is None:
         message.alert("No Ship called: %s" % (params.group(6),))
         return
     
     scan = p.scan("P")
     if scan is None:
         message.reply("No planet scans available on %s:%s:%s" % (p.x,p.y,p.z,))
         return
     
     planetscan = scan.planetscan
     tick=scan.tick
     res_m=planetscan.res_metal
     res_c=planetscan.res_crystal
     res_e=planetscan.res_eonium
     prod_res=planetscan.prod_res
     rand_id=scan.pa_id
     
     cost_m=ship.metal
     cost_c=ship.crystal
     cost_e=ship.eonium
     total_cost=ship.total_cost
     
     class_factory_table = {'Fighter': 'factory_usage_light', 'Corvette': 'factory_usage_light', 'Frigate': 'factory_usage_medium',
                            'Destroyer': 'factory_usage_medium', 'Cruiser': 'factory_usage_heavy', 'Battleship': 'factory_usage_heavy'}
     prod_modifier_table = {'None': 0, 'Low': 33, 'Medium': 66, 'High': 100}
     
     capped_number=min(res_m/cost_m, res_c/cost_c, res_e/cost_e)
     overflow=res_m+res_c+res_e-(capped_number*(cost_m+cost_c+cost_e))
     buildable = capped_number + ((overflow*.95)/total_cost)
     
     demo = 1/(1+PA.getfloat("demo","prodcost"))
     total = 1/(1+PA.getfloat("total","prodcost"))
     reply="Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (p.x,p.y,p.z,rand_id,tick)
     reply+=" can purchase %s: %s | Demo: %s | Total: %s"%(ship.name,int(buildable),int(buildable*demo),int(buildable*total))
     
     if prod_res > 0:
         factory_usage=getattr(planetscan,class_factory_table[ship.class_])
         max_prod_modifier=prod_modifier_table[factory_usage]
         buildable_from_prod = buildable + max_prod_modifier*(prod_res)/100/total_cost
         reply+=" Counting %d res in prod at %s usage:" % (prod_res,factory_usage)
         reply+=" %s | Demo: %s | Total: %s "%(int(buildable_from_prod), int(buildable_from_prod*demo),int(buildable*total))
     
     message.reply(reply)
开发者ID:Go3Media,项目名称:merlin,代码行数:50,代码来源:afford.py

示例13: execute

    def execute(self, message, user, params):
        
        name, ticks, factories = params.group(1,2,3)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("%s is not a ship." % name)
            return
        ticks = int(ticks)
        factories = int(factories)

        race = ship.race[:3].lower()
        race = "etd" if race == "eit" else race

        gov = None
        pop = 0
        for p in (params.group(4) or "").split():
            m=self.govre.match(p)
            if m and not gov:
                gov=m.group(1).lower()
                continue
            if p.isdigit() and not pop:
                pop = int(p)
                continue

        m = ship.metal
        c = ship.crystal
        e = ship.eonium
        bonus = 1 + pop/100.0
        if gov:
            m *= (1+PA.getfloat(gov,"prodcost"))
            c *= (1+PA.getfloat(gov,"prodcost"))
            e *= (1+PA.getfloat(gov,"prodcost"))
            bonus += PA.getfloat(gov,"prodtime")
        if race:
            bonus += PA.getfloat(race,"prodtime")
        cost = floor(m)+floor(c)+floor(e)

        res = int(self.revprod(ticks, factories, bonus))
        ships = int(res / cost)

        reply = "You can build %s %s (%s) in %d ticks" % (self.num2short(ships), ship.name, self.num2short(ships*ship.total_cost//PA.getint("numbers", "ship_value")), ticks)
        reply += " using %s factories" % (factories,) if factories > 1 else ""
        reply += " with a" if race or gov else ""
        reply += " %s"%(PA.get(gov,"name"),) if gov else ""
        reply += " %s"%(PA.get(race,"name"),) if race else ""
        reply += " planet" if race or gov else ""
        reply += " with %s%% population"%(pop,) if pop else ""
        message.reply(reply)
开发者ID:JDD,项目名称:merlin,代码行数:49,代码来源:rprod.py

示例14: execute

    def execute(self, message, user, params):
        
        num, name, factories = params.group(1,2,3)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("%s is not a ship." % name)
            return
        num = self.short2num(num)
        factories = int(factories)

        race = gov = None
        pop = 0
        for p in (params.group(4) or "").split():
            m=self.racere.match(p)
            if m and not race:
                race=m.group(1).lower()
                continue
            m=self.govre.match(p)
            if m and not gov:
                gov=m.group(1).lower()
                continue
            if p.isdigit() and not pop:
                pop = int(p)
                continue

        cost = ship.total_cost
        bonus = 1 + pop/100.0
        if gov:
            cost *= (1+PA.getfloat(gov,"prodcost"))
            bonus += PA.getfloat(gov,"prodtime")
        if race:
            bonus += PA.getfloat(race,"prodtime")

        ticks = self.calc_ticks(cost, num, bonus, factories)

        reply = "It will take %s ticks to build %s %s (%s)" % (ticks, self.num2short(num), ship.name, self.num2short(num*ship.total_cost/100))
        reply += " using %s factories" % (factories,) if factories > 1 else ""
        reply += " with a" if race or gov else ""
        reply += " %s"%(PA.get(gov,"name"),) if gov else ""
        reply += " %s"%(PA.get(race,"name"),) if race else ""
        reply += " planet" if race or gov else ""
        reply += " with %s%% population"%(pop,) if pop else ""
        message.reply(reply)
开发者ID:munin,项目名称:merlin,代码行数:44,代码来源:prod.py

示例15: execute

    def execute(self, message, user, params):
        
        name, ticks, factories = params.group(1,2,3)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("%s is not a ship." % name)
            return
        ticks = int(ticks)
        factories = int(factories)

        race = gov = None
        pop = 0
        for p in (params.group(4) or "").split():
            m=self.racere.match(p)
            if m and not race:
                race=m.group(1).lower()
                continue
            m=self.govre.match(p)
            if m and not gov:
                gov=m.group(1).lower()
                continue
            if p.isdigit() and not pop:
                pop = int(p)
                continue

        cost = ship.total_cost
        bonus = 1 + pop/100.0
        if gov:
            cost *= (1+PA.getfloat(gov,"prodcost"))
            bonus += PA.getfloat(gov,"prodtime")
        if race:
            bonus += PA.getfloat(race,"prodtime")

        res = int(self.revprod(ticks, factories, bonus))
        ships = int(res / cost)

        reply = "You can build %s %s (%s) in %d ticks" % (self.num2short(ships), ship.name, self.num2short(ships*ship.total_cost/100), ticks)
        reply += " with a" if race or gov else ""
        reply += " %s"%(PA.get(gov,"name"),) if gov else ""
        reply += " %s"%(PA.get(race,"name"),) if race else ""
        reply += " planet" if race or gov else ""
        reply += " with %s%% population"%(pop,) if pop else ""
        message.reply(reply)
开发者ID:Go3Media,项目名称:merlin,代码行数:44,代码来源:rprod.py


注:本文中的Core.maps.Ship类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。