Esempio n. 1
0
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()
Esempio n. 2
0
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()
Esempio n. 3
0
    def execute(self, message, user, params):

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

        num = self.short2num(num)
        ship = Ship.load(name=name)
        if ship is not None:
            pass
        elif "asteroids".rfind(name.lower()) > -1:
            ship = Ship(name="Asteroids",
                        class_="Roids",
                        armor=50,
                        total_cost=PA.getint("numbers", "roid_value") *
                        PA.getint("numbers", "ship_value"))
        elif "constructions".rfind(name.lower()) > -1:
            ship = Ship(name="Constructions",
                        class_="Struct",
                        armor=500,
                        total_cost=PA.getint("numbers", "cons_value") *
                        PA.getint("numbers", "ship_value"))
        else:
            message.alert("No Ship called: %s" % (name, ))
            return
        efficiency = PA.getfloat("teffs", attacker.lower())
        attacker_class = getattr(Ship, attacker)
        attackers = session.query(Ship).filter(attacker_class == ship.class_)
        if attackers.count() == 0:
            message.reply("%s are not hit by anything as that category (%s)" %
                          (ship.name, attacker))
            return
        if ship.class_ == "Roids":
            reply = "Capturing"
        elif ship.class_ == "Struct":
            reply = "Destroying"
        else:
            reply = "Stopping"
        reply += " %s %s (%s) as %s requires " % (
            num, ship.name,
            self.num2short(num * ship.total_cost /
                           PA.getint("numbers", "ship_value")), attacker)
        for attacker in attackers:
            if attacker.type.lower() == "emp":
                needed = int((math.ceil(
                    num / (float(100 - ship.empres) / 100) / attacker.guns)) /
                             efficiency)
            else:
                needed = int(
                    (math.ceil(float(ship.armor * num) / attacker.damage)) /
                    efficiency)
            reply += "%s: %s (%s) " % (attacker.name, needed,
                                       self.num2short(
                                           attacker.total_cost * needed /
                                           PA.getint("numbers", "ship_value")))
        message.reply(reply)
Esempio n. 4
0
 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)
Esempio n. 5
0
    def execute(self, message, user, params):
        
        count = self.short2num(params.group(1) or "1")
        name = params.group(2)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("No Ship called: %s" % (name,))
            return
        
        Q = session.query(User, UserFleet)
        Q = Q.join(User.fleets)
        Q = Q.filter(User.active == True)
        Q = Q.filter(User.access >= Config.getint("Access", "member"))
        Q = Q.filter(UserFleet.ship == ship)
        Q = Q.filter(UserFleet.ship_count >= count)
        Q = Q.filter(User.fleetcount > 0)
        Q = Q.order_by(desc(UserFleet.ship_count))
        result = Q.all()
        
        if len(result) < 1:
            message.reply("There are no planets with free fleets and at least %s ships matching '%s'"%(self.num2short(count),ship.name))
            return
        
        tick = Updates.current_tick()
        reply = "Fleets matching query: "
        reply+= " // ".join(map(lambda (u, x): "%s(%s) %s: %s %s ((%s))"%(u.name,u.fleetupdated-tick,u.fleetcount,self.num2short(x.ship_count),ship.name,u.fleetcomment),result))
        message.reply(reply)
Esempio n. 6
0
File: cost.py Progetto: munin/merlin
 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)
Esempio n. 7
0
    def execute(self, message, user, params):

        search = params.group(1)

        Q = session.query(FleetLog)

        if search is not None:
            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)
Esempio n. 8
0
    def execute(self, message, user, params):

        count = self.short2num(params.group(1) or "1")
        name = params.group(2)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("No Ship called: %s" % (name, ))
            return

        Q = session.query(User, UserFleet)
        Q = Q.join(User.fleets)
        Q = Q.filter(User.active == True)
        Q = Q.filter(User.access >= Config.getint("Access", "member"))
        Q = Q.filter(UserFleet.ship == ship)
        Q = Q.filter(UserFleet.ship_count >= count)
        Q = Q.filter(User.fleetcount > 0)
        Q = Q.order_by(desc(UserFleet.ship_count))
        result = Q.all()

        if len(result) < 1:
            message.reply(
                "There are no planets with free fleets and at least %s ships matching '%s'"
                % (self.num2short(count), ship.name))
            return

        tick = Updates.current_tick()
        reply = "Fleets matching query: "
        reply += ", ".join(
            map(
                lambda (u, x): "%s(%s) %s: %s %s" %
                (u.name, u.fleetupdated - tick, u.fleetcount,
                 self.num2short(x.ship_count), ship.name), result))
        message.reply(reply)
Esempio n. 9
0
    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 (%s) will cost %s metal, %s crystal and %s eonium." % (
            num, ship.name,
            self.num2short(
                ship.total_cost * num // PA.getint("numbers", "ship_value")),
            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(floor(ship.metal * (1 + bonus)) * num),
                self.num2short(floor(ship.crystal * (1 + bonus)) * num),
                self.num2short(floor(ship.eonium * (1 + bonus)) * num))

        reply += " It will add %s value" % (self.num2short(
            ship.total_cost * num *
            (1.0 / PA.getint("numbers", "ship_value") -
             1.0 / PA.getint("numbers", "res_value"))), )
        message.reply(reply)
Esempio n. 10
0
    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)
Esempio n. 11
0
    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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 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(str(ship))
Esempio n. 14
0
File: ship.py Progetto: JDD/DLR
 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)
Esempio n. 15
0
    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()
Esempio n. 16
0
 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
Esempio n. 17
0
    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])
Esempio n. 18
0
    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)
Esempio n. 19
0
 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
Esempio n. 20
0
    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 = 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)
        print cost

        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 / PA.getint("numbers", "ship_value")))
        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)
Esempio n. 21
0
File: shipstats.py Progetto: JDD/DLR
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()
Esempio n. 22
0
    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):
            scanlog("%s: %s" % m.groups())

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

        session.commit()
Esempio n. 23
0
def add_ship(dct):
    ship = Ship()
    for key in dct.keys():
        if dct[key] != "-":
            if key == "class":
                k = key + "_"
            elif key[:4] == "init":
                k = "init"
            elif key[:6] == "target":
                k = "t" + key[-1]
            else:
                k = key
            setattr(ship, k, dct[key])
    ship.total_cost = int(ship.metal) + int(ship.crystal) + int(ship.eonium)
    session.add(ship)
    if __name__ == '__main__':
        print "%12s%12s%12s%12s" % (
            ship.name,
            ship.class_,
            ship.race,
            ship.type,
        )
Esempio n. 24
0
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()
Esempio n. 25
0
 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)
Esempio n. 26
0
File: rprod.py Progetto: JDD/merlin
    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)
Esempio n. 27
0
File: prod.py Progetto: munin/merlin
    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)
Esempio n. 28
0
    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)
Esempio n. 29
0
 def drop_ships(self, user, taker, ships):
     removed = {}
     tick = Updates.current_tick()
     count = None
     for name in ships.split():
         if not count:
             mc = self.countre.match(name)
             if mc:
                 count = self.short2num(mc.group(1))
                 continue
         ship = Ship.load(name=name)
         if ship is None:
             count = None
             continue
         for fleet in user.fleets.filter_by(ship=ship):
             removed[fleet.ship.name] = count or fleet.ship_count
             self.delete_ships(user, taker, fleet, tick, count)
             count = None
     session.commit()
     return removed
Esempio n. 30
0
 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
     
     feud = PA.getfloat("feud","prodcost")
     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))
     reply+=" Feudalism: %s metal, %s crystal and %s eonium."%(
             self.num2short(ship.metal*(1+feud)*num),
             self.num2short(ship.crystal*(1+feud)*num),
             self.num2short(ship.eonium*(1+feud)*num))
     reply+=" It will add %s value"%(self.num2short(ship.total_cost*num/100),)
     message.reply(reply)
Esempio n. 31
0
File: stop.py Progetto: munin/merlin
 def execute(self, message, user, params):
     
     num, name, attacker = params.groups()
     attacker = (attacker or "t1").lower()
     
     num = self.short2num(num)
     ship = Ship.load(name=name)
     if ship is not None:
         pass
     elif "asteroids".rfind(name.lower()) > -1:
         ship = Ship(name="Asteroids",class_="Roids",armor=50,total_cost=PA.getint("numbers", "roid_value")*100)
     elif "constructions".rfind(name.lower()) > -1:
         ship = Ship(name="Constructions",class_="Struct",armor=500,total_cost=PA.getint("numbers", "cons_value")*100)
     else:
         message.alert("No Ship called: %s" % (name,))
         return
     efficiency = PA.getfloat("teffs",attacker.lower())
     attacker_class = getattr(Ship, attacker)
     attackers = session.query(Ship).filter(attacker_class == ship.class_)
     if attackers.count() == 0:
         message.reply("%s are not hit by anything as that category (%s)" % (ship.name,attacker))
         return
     if ship.class_ == "Roids":
         reply="Capturing"
     elif ship.class_ == "Struct":
         reply="Destroying"
     else:
         reply="Stopping"
     reply+=" %s %s (%s) as %s requires " % (num, ship.name,self.num2short(num*ship.total_cost/100),attacker)
     for attacker in attackers:
         if attacker.type.lower() == "emp" :
             needed=int((math.ceil(num/(float(100-ship.empres)/100)/attacker.guns))/efficiency)
         else:
             needed=int((math.ceil(float(ship.armor*num)/attacker.damage))/efficiency)
         reply+="%s: %s (%s) " % (attacker.name,needed,self.num2short(attacker.total_cost*needed/100))
     message.reply(reply)
Esempio n. 32
0
 def update_fleets(self, user, ships):
     user.fleets.delete()
     for ship, count in ships.items():
         s = Ship.load(ship)
         user.fleets.append(UserFleet(ship_id=s.id, ship_count=count))
Esempio n. 33
0
    def execute(self, message, user, params):

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

        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 //
                               PA.getint("numbers", "ship_value")),
                killed,
                self.num2short(killed * PA.getint("numbers", "roid_value")),
            ))
            return
        if ship.t1 == "Resources":
            killed = total_damage * 50
            message.reply("%s %s (%s) will capture Resource: %s (%s)" % (
                num,
                ship.name,
                self.num2short(num * ship.total_cost //
                               PA.getint("numbers", "ship_value")),
                self.num2short(killed),
                self.num2short(killed // PA.getint("numbers", "res_value")),
            ))
            return
        if ship.t1[:6] == "Struct":
            killed = total_damage // 500
            message.reply("%s %s (%s) will destroy Structure: %s (%s)" % (
                num,
                ship.name,
                self.num2short(num * ship.total_cost //
                               PA.getint("numbers", "ship_value")),
                killed,
                self.num2short(killed * PA.getint("numbers", "cons_value")),
            ))
            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 //
                           PA.getint("numbers", "ship_value")), target_class)
        if ship.type.lower()[:4] == "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 //
                                           PA.getint("numbers", "ship_value")))
        message.reply(reply)
Esempio n. 34
0
    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)