;ò ÖMâ>c@s•dZdkZdkZdkZdkZdkZdkZdfd„ƒYZd„ZeƒdZ dZ dei dei d ei d ei d Z d ei d ei dZ eide de de dƒZeidƒZd„ZdZdZdZdZdedededZdZeidedededƒZd„Zd „Zd!„Zd"„Zd#„Zd$„ZdS(%sFAllows embedded python expressions to reference the internal database.NsdelayedBindingcBstZdZeZeZx¥ddfddfddfddfd d fd d fd dfddfddfddfddfddfddfg D](\ZZdeddeddUq”WxŠd dfd!dfd"dfd#dfd$d fd%d fd&dfd'dfd(dfd)dfg D](\ZZdedded*dUq!Wx®d+d,fd-d.fd/d0fd1d2fd3d4fd5d6fd7d8fd9d:fd;d<fd=d>fd?d@fdAdBfdCdDfdEdFfgD](\ZZdedGdedHdUqÒWdI„ZdJ„Z dK„Z RS(LsMDelays a binding of a variable until runtime. This is a total hack! s__add__sself.operator.adds__sub__sself.operator.subs__mul__sself.operator.muls__div__sself.operator.divs__mod__sself.operator.mods __lshift__sself.operator.lshifts __rshift__sself.operator.__rshift__s__and__sself.operator.__and__s__or__sself.operator.__or__s__xor__sself.operator.xors __concat__sself.operator.concats __repeat__sself.operator.repeats__cmp__scmpsdef s(self, other): s return s(self.convertField(), other) Ns__radd__s__rsub__s__rmul__s__rdiv__s__rmod__s __rlshift__s __rrshift__s__rand__s__ror__s__rxor__s(other, self.convertField()) s__neg__sself.operator.negs__pos__sself.operator.poss__abs__sself.operator.abss __invert__sself.operator.invs__not__sself.operator.__not__s__int__sints__long__slongs __float__sfloats__oct__socts__hex__shexs __nonzero__sself.operator.truths__hash__shashs__str__sstrs__repr__sreprs(self): s(self.convertField()) cCs ||_dS(N(snamesself(sselfsname((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys__init__qscOst|iƒ||ƒSdS(N(sapplysselfs convertFieldsargsskw(sselfsargsskw((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys__call__sscCscy:t|iƒo|i|iƒ}n|i|i}Wntj o}t|‚nX|SdS(N(scallablesselfsnames delayedValuesvalsKeyErrorses NameError(sselfsesval((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys convertFieldus ( s__name__s __module__s__doc__sNones delayedValuesoperatorsisjs__init__s__call__s convertField(((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pysdelayedBindingFs | a …   c 8Csdddfdddfddfddd „fd d d „fg} d ddfdddfddfddfddfddfddfddfddfddfddfddfddfg }| |ddfdddfddd fd!dfd"d#fd$d#fd%d#fd&dfd'dfd(dd)fd*dfd+dd,fd-dd.„fd/dfd0dfd1dfd2dfd3dfd4dfd5dfd6dd7fd8dd9fd:dfd;dd<fd=d>fd?d>fd@d>fdAd>fdBd>fdCd>fdDd>fdEd>fdFd>fdGd>fdHd>fdId>fdJd>fdKd>fdLd>dMfdNd>dOfdPd>dQfdRd>dSfdTd>dUfdVd>dWfdXd>dYfdZd>d[fd\d>d]fd^d>d_fd`d>dafdbd>dcfddd>defdfd>dgfdhddi„fg5}| djdfdddfddd fdkdfdlddmfg}||dnddofdpddqfdrdfdsddtfduddvfdwddofd;dfg}|dxdfdydfdzdfd{dfd|dfd}dd~fddd€fddfdwddxfg }||d{dfd|dfd‚d>fdzdfd}ddƒfd„dd…fdrdfddfdsddtfdwdd‚fd;dfg } | d†dd‡fg}dˆdd‰„fdŠdd‹„fg}dŒddfdŽddfg}d„} hd‘| |ƒ<d’| |ƒ<d“| |ƒ<d”| | ƒ<d•| |ƒ<d–| |ƒ<d—| |ƒ“ssdistanceicCs|d|dd„S(NsxsycCsti||f||fƒS(N(sempDbssectorDistances__fromxs__fromysxsy(sxsys__fromxs__fromy((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys—s(sldb(sldb((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys–sscivilscivsmilitsmilsshellsgunsironsdustsbarsfoodsoilslcmshcmsuwsradsdessefficseffsmobilsmobsterrsterr1isterr2sterr3sroadsrailsdfensesdefensesworkscoastalscoastsnewdescCs$|ddjo|dp|dS(Nssdess_sdes(sldb(sldb((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys©ssminsgoldsfertsocontentsuransoldownsoffsxdistsdist_xsydistsdist_ysavailspetrolspetsc_distism_distsu_distss_distsg_distsp_distsi_distsd_distsb_distsf_distso_distsl_distsh_distsr_distsc_delsc_cutsm_delsm_cutsu_delsu_cutss_delss_cutsg_delsg_cutsp_delsp_cutsi_delsi_cutsd_delsd_cutsb_delsb_cutsf_delsf_cutso_delso_cutsl_delsl_cutsh_delsh_cutsr_delsr_cutsdistcCsd|d|dfS(Ns%s,%ssdist_xsdist_y(sldb(sldb((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pysÀsstypestechsuidsidsfleetsfltsnplanesplnsfuelsnxlightsxls nchoppersshesgroupswingsrangesshipsattsdefshardenshardsnuketypesnukeslandsarmysfortsretreatsretrsnumbersnumsxmaxcCs |ddS(Ns worldsizei(sldb(sldb((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pysðssymaxcCs |ddS(Ns worldsizei(sldb(sldb((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pysñsscmaxsmaxCivsumaxsmaxUWcCs”h}xƒ|D]{}t|ƒdjo|d}n |d}t|ƒ}x;t|dt|dƒdƒD]}|||d| \d*)s (?Ps)(?::(?Ps ))?,(?Ps)(?::(?Ps))?s @(?Ps ),(?Ps):(?P\d+)s^\*$|^s$|^s$s>^(?P\S+?)(?P[=<>#])(?P\S+?)(?:&(?P\S+))?$c Cs¶ti|ƒ} | o td‚n| idƒtj oc| idƒdjo d} nt| idƒƒ} yt i d| }Wnt j otd‚nX|\}}}}||jo.ttiddftt||fƒƒ} n2||jod||fg} nd |g} ||jo2| ttid d ftt||fƒƒ} qM||jo| id ||fƒqM| id |ƒn±| idƒoj| idƒo‡tt| iddƒƒ\}}||jo+ttiddf| iddƒƒ} qZ||jod| iddƒg} qZnd| idƒg} | idƒott| iddƒƒ\}}||jo/| ttid d f| iddƒƒ} q||jo!| id| iddƒƒqqM| id| idƒƒn7| idƒo d| idddƒg} ng} xB|o:ti|ƒ} | o td‚ng}x§| iddƒD]“} t| ƒdjo| tij o|it| ƒƒq”ti dƒi| ƒot!|i#| ƒ o|it| ƒƒq”|i| ƒq”W| id|dhd d!<d"d#<d$d$<d%d%<| id&ƒ|dfƒ| id'ƒ}qPW| od(Snti$| d)ƒSd*S(+sŒConvert a standard empire range/selectors to a python expression. This takes a range of the form 'x1:x2,y1:y2', 'x,y', '#?', or '*' (all the possible empire ranges) and a cond of the form 'var[#=<>]var&...', and converts it to a valid python expression. (IE. 'xl>=x1 and xl<=x2 and yl>=y1 and yl<=y2 and var==var and ...'). The result of this can then be passed to getSectors or foreach to return a list of db items that apply. Note: This function does not check for ownership. Frequently, the string 'owner==-1 and ' is preprended to the output of this function to force it to only apply to owned objects. sCoordinate regexp failure.srealmsisRealm not in database.sxl>=sxl<=s(xl >= %d or xl <= %d)sxl==%dsyl>=syl<=s(yl >= %d or yl <= %d)syl==%dsminXsmaxXs(xl >= %s or xl <= %s)sxl==smaxYsminYs(yl >= %s or yl <= %s)syl==scirXsdistance(%s,%s)<=%sscirYscirDsCondition regexp failure.svarsvalis^[a-z][a-z0-9_]+$s%s%s%ss=s==s#s!=ssoprsnexts1s and N(%s sectorsFormatsmatchsrangesmcserrorsgroupsNonesrmsintsempDbsmegaDBsvalsKeyErrorsminXsmaxXsminYsmaxYsmapsoperatorsaddsstrs conditionssappendscondsconditionsFormatsvarssislensstringsdigitssreprsrescompiles selectorssdbnameshas_keysjoin( sdbnamesrangescondsmaxXsmaxYsvarssvalsminXsminYsrms conditionssmcsi((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys selectToExpr0s~        !  !!  %  $.Ss[^\]"']s'.*?'s".*?"s (?P
.*?)s(?P(?:s|s)*)s(?P.*)s^s\[s\]cCs”d}x|owti|ƒ}|o|d|
}Pn|d|idƒ
}|idƒ}|idƒ}|d|d}q	W|dSd	S(
sÝConvert a string with embedded python expressions to an expression.

    This takes a string of the form 'text_1 [expr1] text_2 [expr2] ...' and
    converts it to ('text_1 '+str(expr1)+' text_2 '+str(expr2)+' ...').
    ss+spresevalsposts+str((s))iN(scmdstxts
exprFormatsmatchsmcsgroupse(stxtscmdsesmc((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys
estrToExpr”scCsVt|}|t_yt||ƒSWn+td|ft	t
iƒd ƒ‚nXdS(s-Evaluate an expression and return the result.s1Evaluate error!
"%s" raised %s with detail:
"%s".iN(s	selectorssdbnamesenviosdbsdelayedBindingsdelayedValuesevalsexprserrorstuplessyssexc_info(sexprsdbnamesdbsenvio((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys
evalString©s
	cBsie|}ddddddd|dd	d
|fdU|d}|d=|ei|eƒSdS(
sExecute a string for every item in a database.

    This is an internal function that is called by several functions below.
    This is really just useful for code consolidation.  The execStr
    parameter is very specific to the code block found within this
    function.
    sdef __func(__db, __class):
s
 __list = []
s __db = __db.items()
s
 __db.sort()
s for __db in __db:
s!  __class.delayedValue = __db[1]
s  try:
s  except NameError, e:
s   pass
s return __list
Ns__func(s	selectorssdbnamesenviosexecStrsfsempDbsmegaDBsdelayedBinding(sdbnamesexecStrsfsenvio((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys
execCodeblock´s
6
cCsKyt|d|dƒSWn+td|fttiƒd ƒ‚nXdS(sðGiven a python expression, return all db keys that apply.

    This functions takes a valid python expression (expr), evaluates it for
    every item in empDb.megaDB[dbname] and then returns a list of all the
    keys that tested true.
    s   if (s): __list.append(__db[0])
s9GetSectors error in "%s"!
Exception %s with detail:
"%s".iN(s
execCodeblocksdbnamesexprserrorstuplessyssexc_info(sexprsdbname((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys
getSectorsÍscCs’yt|d|ƒ}Wn+td|fttiƒd ƒ‚nXh}t	t
tigt
|ƒt	ti|fft
|ƒ|ƒƒ|SdS(s'Given a python expression, return a database with all that apply.

    This functions takes a valid python expression (expr), evaluates it for
    every item in empDb.megaDB[dbname] and then returns a database containg
    all the sector key/value pairs that tested true for the expression.
    s    if (%s): __list.append(__db)
s;GetSectorDBs error in "%s"!
Exception %s with detail:
"%s".iN(s
execCodeblocksdbnamesexprslistserrorstuplessyssexc_infosdictsmapsapplysoperatorssetitemslensadd(sexprsdbnameslistsdict((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pysgetSectorDBsÝs(&cCsVy!t|d|d|dƒSWn.td||fttiƒd ƒ‚nXdS(s)Combination of getSectors and evalString.s   if (s): __list.append((s))
s;Foreach error in "%s"/"%s"!
Exception %s with detail:
"%s".iN(s
execCodeblocksdbnames	cond_exprstxt_exprserrorstuplessyssexc_info(s	cond_exprstxt_exprsdbname((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pysforeachs(s__doc__sstringsresoperatorssyssempDbsempParsesdelayedBindingsinitializeSelectorsserrorss_realmsss_sects	s_sectorss
s_circularscompiles
sectorsFormatsconditionsFormatsselectToExprs	ss_normals
ss_quoted1s
ss_quoted2ss_press_evalss_posts
exprFormats
estrToExprs
evalStrings
execCodeblocks
getSectorssgetSectorDBssforeach(s
sectorsFormatss_posts	s_sectorssempDbsoperators
exprFormatss_evals
s_circularsdelayedBindingsresgetSectorDBssforeachsconditionsFormatsstringsempParsessyssinitializeSelectorsss_realmss_pres
evalStrings
getSectorssselectToExprs	ss_normals
execCodeblockserrors
ss_quoted1s
estrToExprs
ss_quoted2((s?/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empEval.pys?s:						-G	2'	]'					3