本文整理汇总了Python中Core.maps.Planet.load方法的典型用法代码示例。如果您正苦于以下问题:Python Planet.load方法的具体用法?Python Planet.load怎么用?Python Planet.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core.maps.Planet
的用法示例。
在下文中一共展示了Planet.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def execute(self, message, user, params):
if params.group(4) is None:
target = Planet.load(*params.group(1,3,5))
if target is None:
message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
return
attacker = self.get_user_planet(user)
else:
target = Planet.load(*params.group(1,3,5))
if target is None:
message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
return
attacker = Planet.load(*params.group(6,8,10))
if attacker is None:
message.alert("No planet with coords %s:%s:%s" % params.group(6,8,10))
return
reply="Target "
target_val = target.value
attacker_val = attacker.value
target_score = target.score
attacker_score = attacker.score
reply+="%s:%s:%s (%s|%s) "%(target.x,target.y,target.z,
self.num2short(target.value),self.num2short(target.score))
reply+="| Attacker %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
self.num2short(attacker.value),self.num2short(attacker.score))
reply+="| Bravery: %.2f " % (attacker.bravery(target),)
cap=target.maxcap(attacker)
xp=attacker.calc_xp(target)
reply+="| Roids: %s | XP: %s | Score: %s" % (cap,xp,xp*60)
message.reply(reply)
示例2: execute
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def execute(self, message, user, params):
if len(params.groups()) == 1:
target = Planet(size=int(params.group(1)))
attacker = None
elif params.group(4) is None:
target = Planet.load(*params.group(1,3,5))
if target is None:
message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
return
if self.user_has_planet(user):
attacker = user.planet
else:
attacker = None
else:
target = Planet.load(*params.group(1,3,5))
if target is None:
message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
return
attacker = Planet.load(*params.group(6,8,10))
if attacker is None:
message.alert("No planet with coords %s:%s:%s" % params.group(6,8,10))
return
reply = ""
total = 0
for i in range(1,5):
cap = target.maxcap(attacker)
total += cap
reply+="Wave %d: %d (%d), " % (i,cap,total,)
target.size -= cap
message.reply("Caprate: %s%% %s"%(int(target.caprate(attacker)*100),reply.strip(', ')))
示例3: __init__
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def __init__(self, message, m):
scanlog(asctime())
try:
pnick = "(%s)" % message.get_pnick()
except:
pnick = ""
scanlog("Galaxy status from %s%s" % (message.get_nick(), pnick))
target_x=m.group(1)
target_y=m.group(2)
target_z=m.group(3)
owner_x=m.group(4)
owner_y=m.group(5)
owner_z=m.group(6)
mission=m.group(7)
fleetname=m.group(8)
# race=m.group(10)
fleetsize=m.group(11)
eta=m.group(12)
if mission == "A":
mission = "Attack"
elif mission == "D":
mission = "Defend"
elif mission == "R":
mission = "Return"
target=Planet.load(target_x,target_y,target_z)
if target is None:
return
owner=Planet.load(owner_x,owner_y,owner_z)
if owner is None:
return
curtick=Updates.current_tick()
landing_tick = int(eta) + int(curtick)
scanlog("%s:%s:%s %s:%s:%s '%s' %s %s eta %s" % (owner_x,owner_y,owner_z,target_x,target_y,target_z,fleetname,fleetsize,mission,eta))
fleet = FleetScan(owner=owner, target=target, fleet_size=fleetsize, fleet_name=fleetname, landing_tick=landing_tick, mission=mission)
fleet.in_cluster = owner_x == target_x
fleet.in_galaxy = fleet.in_cluster and owner_y == target_y
try:
session.add(fleet)
session.commit()
except IntegrityError,e:
session.rollback()
print "Exception in galstatus: "+e.__str__()
scanlog("Exception in galstatus: "+e.__str__())
traceback.print_exc()
示例4: planet
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def planet(self, message, user, params):
target = Planet.load(*params.group(1,3,5))
if target is None:
message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
return
attacker = Planet.load(*params.group(6,8,10))
if attacker is None:
message.alert("No planet with coords %s:%s:%s" % params.group(6,8,10))
return
self.execute(message, target, attacker)
示例5: execute
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def execute(self, request, user, id, x, y, z, when):
planet = Planet.load(x,y,z)
if planet is None:
return self.attack(request, user, id, "No planet with coords %s:%s:%s" %(x,y,z,))
tick = Updates.current_tick()
when = int(when)
if when < PA.getint("numbers", "protection"):
eta = when
when += tick
elif when <= tick:
return self.attack(request, user, id, "Can not book targets in the past. You wanted tick %s, but current tick is %s." % (when, tick,))
else:
eta = when - tick
if when > 32767:
when = 32767
if planet.intel and planet.alliance and planet.alliance.name == Config.get("Alliance","name"):
return self.attack(request, user, id, "%s:%s:%s is %s in %s. Quick, launch before they notice!" % (x,y,z, planet.intel.nick or 'someone', Config.get("Alliance","name"),))
try:
planet.bookings.append(Target(user=user, tick=when))
session.commit()
except IntegrityError:
session.rollback()
target = planet.bookings.filter(Target.tick == when).first()
if target is not None:
return self.attack(request, user, id, "Target %s:%s:%s is already booked for landing tick %s by user %s" % (x,y,z, when, target.user.name,))
else:
return self.attack(request, user, id, "Booked landing on %s:%s:%s tick %s (eta %s) for user %s" % (x,y,z, when, (when-tick), user.name,))
return self.attack(request, user, id)
示例6: execute
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
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)
示例7: planet
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def planet(self, message, user, params):
planet = Planet.load(*params.group(1,3,5))
if planet is None:
message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
return
# List of last 10 scans
if params.group(6) == "o":
scans = planet.scans.filter_by(scantype=self.type).order_by(desc(Scan.id))[:10]
if len(scans) < 1:
message.reply("No %s Scans of %s:%s:%s found"%(PA.get(self.type,"name"),planet.x,planet.y,planet.z))
return
prev = []
for scan in scans:
prev.append("(pt%s %s)" % (scan.tick, scan.pa_id,))
reply = "Last 10 %s Scans on %s:%s:%s "%(PA.get(self.type,"name"),planet.x,planet.y,planet.z) + " ".join(prev)
message.reply(reply)
return
# Latest scan
scan = planet.scan(self.type)
if scan is None:
message.reply("No %s Scans of %s:%s:%s found"%(PA.get(self.type,"name"),planet.x,planet.y,planet.z))
return
# Link to scan
if params.group(7) == "l":
reply = "%s on %s:%s:%s " % (scan.type,planet.x,planet.y,planet.z,)
reply+= self.url(scan.link, user)
message.reply(reply)
return
# Display the scan
message.reply(self.url(str(scan), user))
示例8: execute
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def execute(self, request, user, x, y, z, fleets=False):
week = Updates.week_tick()
planet = Planet.load(x,y,z)
if planet is None:
return HttpResponseRedirect(reverse("planet_ranks"))
Q = session.query(FleetScan, Planet, Alliance)
Q = Q.join(FleetScan.target)
Q = Q.outerjoin(Planet.intel).outerjoin(Intel.alliance)
Q = Q.filter(FleetScan.owner == planet)
Q = Q.order_by(desc(FleetScan.landing_tick))
if not fleets:
Q = Q.filter(FleetScan.landing_tick >= week)
outgoing = Q.all()
Q = session.query(FleetScan, Planet, Alliance)
Q = Q.join(FleetScan.owner)
Q = Q.outerjoin(Planet.intel).outerjoin(Intel.alliance)
Q = Q.filter(FleetScan.target == planet)
Q = Q.order_by(desc(FleetScan.landing_tick))
if not fleets:
Q = Q.filter(FleetScan.landing_tick >= week)
incoming = Q.all()
scan = planet.scan("A") or planet.scan("U")
return render("iplanet.tpl", request, planet=planet, scan=scan, outgoing=outgoing, incoming=incoming)
示例9: execute
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def execute(self, message, alliance=None, race=None, sortby="score"):
planet = aliased(Planet)
planet_intel = aliased(Intel)
Q = session.query(planet.x, planet.y, planet.z, planet_intel.nick)
Q = Q.outerjoin((planet.intel, planet_intel))
if alliance:
Q = Q.filter(planet_intel.alliance == alliance)
if race:
Q = Q.filter(planet.race == race)
if sortby == "xp":
Q = Q.order_by(desc(planet.xp))
elif sortby == "size":
Q = Q.order_by(desc(planet.size))
elif sortby == "value":
Q = Q.order_by(desc(planet.value))
else:
Q = Q.order_by(desc(planet.score))
result = Q.all()
reply = "Top%s planets" % (" "+race if race is not None else "")
if alliance:
reply+=" in %s"%(alliance.name,)
reply+=" by %s:\n"%(sortby)
prev = []
i=0
for x, y, z, nick in result[:10]:
i+=1
line = "#%2s %12s%s"%(i, "["+nick+"] " if nick else "", Planet.load(x,y,z))
prev.append(line)
message.reply(reply+"\n".join(prev))
示例10: remove
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def remove(self, message, user, params):
id = int(params.group(1))
attack = Attack.load(id)
if attack is None:
message.alert("No attack exists with id %d" %(id))
return
for coord in re.findall(loadable.coord, params.group(2)):
if not coord[4]:
galaxy = Galaxy.load(coord[0],coord[2], active=False)
if galaxy:
attack.removeGalaxy(galaxy)
else:
planet = Planet.load(coord[0],coord[2],coord[4], active=False)
if planet:
attack.removePlanet(planet)
if not len(attack.planets):
session.delete(attack)
session.commit()
if attack in session:
message.reply(str(attack))
else:
message.reply("Deleted Attack %d LT: %d | %s" %(attack.id,attack.landtick,attack.comment,))
示例11: list_fleets
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def list_fleets(self, message, user, params):
# Check the planet exists
planet = Planet.load(*params.group(1,3,5))
if planet is None:
message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
return
# Find all fleets with a known alliance who have defended this planet
OQ = session.query(coalesce(FleetScan.launch_tick, FleetScan.landing_tick), literal_column("'From'").label("dir"), Planet.x, Planet.y, Planet.z, Alliance.name).select_from(FleetScan)
OQ = OQ.filter(FleetScan.target_id == planet.id, FleetScan.in_galaxy==False, FleetScan.mission=="Defend")
OQ = OQ.join(Intel, FleetScan.owner_id == Intel.planet_id).filter(Intel.alliance_id != None)
OQ = OQ.join(Alliance, Intel.alliance_id == Alliance.id).join(Planet, FleetScan.owner_id == Planet.id)
# Find all fleets with a known alliance who have been defended by this planet
TQ = session.query(coalesce(FleetScan.launch_tick, FleetScan.landing_tick), literal_column("'To '").label("dir"), Planet.x, Planet.y, Planet.z, Alliance.name).select_from(FleetScan)
TQ = TQ.filter(FleetScan.owner_id == planet.id, FleetScan.in_galaxy==False, FleetScan.mission=="Defend")
TQ = TQ.join(Intel, FleetScan.target_id == Intel.planet_id).filter(Intel.alliance_id != None)
TQ = TQ.join(Alliance, Intel.alliance_id == Alliance.id).join(Planet, FleetScan.target_id == Planet.id)
# Combine the results into one sorted list
results = sorted(OQ.all()+TQ.all(), reverse=True)
# Quit now if there are no results
if len(results) == 0:
message.reply("No suggestions found")
return
# Reply to the user
message.reply("Tick Dir Planet Alliance")
limit = int(params.group(6) or 5)
for r in results[:limit]:
message.reply("%4s %s %-9s %s" % (r[0], r[1], "%s:%s:%s" % (r[2], r[3], r[4]), r[5]))
if len(results) > limit:
message.reply("%s results not shown (%s total)" % (len(results)-limit, len(results)))
示例12: execute
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def execute(self, page, uid, pa_id, gid=None):
scanlog("Scan: %s (group: %s)" %(pa_id,gid,))
page = decode(page)
m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
if not m:
scanlog("Expired/non-matchinng scan (id: %s)" %(pa_id,))
return
scantype = m.group(1)[0].upper()
x = int(m.group(2))
y = int(m.group(3))
z = int(m.group(4))
tick = int(m.group(5))
m = re.search("<p class=\"right scan_time\">Scan time: ([^<]*)</p>", page)
scantime = m.group(1)
planet = Planet.load(x,y,z,)
try:
Q = session.query(Scan).filter(Scan.pa_id == pa_id).filter(Scan.planet_id == None)
if Q.count() > 0:
scan = Q.first()
else:
scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, time=scantime, group_id=gid, scanner_id=uid)
session.add(scan)
if planet:
planet.scans.append(scan)
session.commit()
scan_id = scan.id
except IntegrityError, e:
session.rollback()
scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
return
示例13: scan
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def scan(self, uid, pa_id, gid=None):
page = urlopen(Config.get("URL","viewscan")%(pa_id,)).read()
page = decode(page)
m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
if not m:
print "Expired/non-matchinng scan (id: %s)" %(pa_id,)
return
scantype = m.group(1)[0].upper()
x = int(m.group(2))
y = int(m.group(3))
z = int(m.group(4))
tick = int(m.group(5))
planet = Planet.load(x,y,z)
if planet is None:
return
try:
scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, group_id=gid, scanner_id=uid)
planet.scans.append(scan)
session.commit()
scan_id = scan.id
except IntegrityError, e:
session.rollback()
print "Scan %s may already exist" %(pa_id,)
print e.__str__()
return
示例14: parse_N
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def parse_N(self, scan_id, scan, page):
#incoming fleets
#<td class=left valign=top>Incoming</td><td valign=top>851</td><td class=left valign=top>We have detected an open jumpgate from Tertiary, located at 18:5:11. The fleet will approach our system in tick 855 and appears to have roughly 95 ships.</td>
for m in re.finditer('<td class="left" valign="top">Incoming</td><td valign="top">(\d+)</td><td class="left" valign="top">We have detected an open jumpgate from ([^<]+), located at (\d+):(\d+):(\d+). The fleet will approach our system in tick (\d+) and appears to have roughly (\d+) ships.</td>', page):
fleetscan = FleetScan()
newstick = m.group(1)
fleetname = m.group(2)
originx = m.group(3)
originy = m.group(4)
originz = m.group(5)
arrivaltick = int(m.group(6))
numships = m.group(7)
fleetscan.mission = "Unknown"
fleetscan.fleet_name = fleetname
fleetscan.launch_tick = newstick
fleetscan.landing_tick = arrivaltick
fleetscan.fleet_size = numships
owner=Planet.load(originx,originy,originz)
if owner is None:
continue
fleetscan.owner = owner
fleetscan.target = scan.planet
try:
scan.fleets.append(fleetscan)
session.commit()
except Exception, e:
session.rollback()
print "Exception in news: "+e.__str__()
traceback.print_exc()
continue
print 'Incoming: ' + newstick + ':' + fleetname + '-' + originx + ':' + originy + ':' + originz + '-' + arrivaltick + '|' + numships
示例15: new
# 需要导入模块: from Core.maps import Planet [as 别名]
# 或者: from Core.maps.Planet import load [as 别名]
def new(self, message, user, params):
tick = Updates.current_tick()
comment = params.group(3) or ""
when = int(params.group(1))
if when < PA.getint("numbers", "protection"):
eta = when
when += tick
elif when <= tick:
message.alert(
"Can not create attacks in the past. You wanted tick %s, but current tick is %s." % (when, tick)
)
return
else:
eta = when - tick
if when > 32767:
when = 32767
attack = Attack(landtick=when, comment=comment)
session.add(attack)
for coord in re.findall(loadable.coord, params.group(2)):
if not coord[4]:
galaxy = Galaxy.load(coord[0], coord[2])
if galaxy:
attack.addGalaxy(galaxy)
else:
planet = Planet.load(coord[0], coord[2], coord[4])
if planet:
attack.addPlanet(planet)
session.commit()
message.reply(str(attack))