; >c@sdZdkZdkZdkZdkZdkZdkZdkZdkZdk Z dk Z dk Z dk Z dfdYZ dfdYZdefdYZdefd YZd efd YZd efd YZdefdYZdefdYZde ifdYZdefdYZdefdYZdefdYZdefdYZdZdZdZdefd YZd!efd"YZd#efd$YZ d%efd&YZ!d'efd(YZ"d)efd*YZ#d+e ifd,YZ$d-e ifd.YZ%d/e ifd0YZ&d1Z'd2Z(d3efd4YZ)d5efd6YZ*d7efd8YZ+d9efd:YZ,d;efd<YZ-d=efd>YZ.d?efd@YZ/dS(As(Synthetic client side command interface.NsEmpParsecBsktZdZdZdZeidZedeeedZ dZ dZ dZ d Z RS( sImplements a set of aliasing commands. This class is used as a wrapper around empQueue.EmpIOQueue. Outgoing commands are sent here, and if they are not client synthetic commands, they are sent to the server via the empQueue module. This class is more 'user-friendly' then the empQueue stuff. The major interaction with this class is done via the Send() module which is passed simple ASCII strings that are to be transmitted. Note: This class generally only has one instantiation - viewer.ioq cCs||_|ii|_|ii|_|ii|_ti|_|_ d|_ dg|_ d|_ g|_ g|_tiddd|iftid|iff|_|itttttttttttt t!t"t#t$t%t&t't(t)t*t+dS(Niss^(?P.*?)\s+s(?P\||(?:>>?!?))s\s*(?P.*?)\s*$s(?P.*)\s*;\s*(?P.*)(,squeuesselfssocks HandleInputsfilenosSendNowsempQueuesQU_SYNCspreFlagspostFlagsrawshisListshisPosspreListspostListsrescompilesSyntaxRedirects SyntaxMultis syntaxLists registerCmdssCmdAliassCmdNullsCmdEvals CmdForEachsCmdBursts CmdDefLists CmdRefreshsCmdExecsCmdOutsCmdNovas CmdPredictsCmdMoversCmdRaws CmdOriginsCmdMMovesCmdEMoves CmdRemovesCmdDannosCmdDteles CmdProjectionsCmdDmoves CmdSetFoodsCmdLTest(sselfsqueue((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys__init__s"      ;     cGsfx_|D]W}|i}|io |i}n |i}x%|D]}t i |||fq=WqWdS(sRegister a list of commands.N( sargsscmdclasssdefaultBindingscmdssdefaultPreListsselfspreListslstspostListscmdsbisectsinsort(sselfsargsscmdclassscmdscmdsslst((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys registerCmdss    s)^\s*(?P\S+)(?:\s+(?P.*))?$ic Cs|tjo t}n|tjo |i}n| o|ii|}|o|i d} t i |i | } | tj o| |||dSnxJ|iD]?}|di|} | tj o|d| |dSqqWt i |i| } | tj o| |||dSq&q*n|tjo |i}n|tjo |i}nti||||} |o|ii| dn|ii| dS(sSearch command line for smart commands. This method is the main way of interacting with this class. Send will search the given command for known smart-commands. If one is found, its associated code block is run. Otherwise, the command is sent unaltered to EmpIOQueue for normal server execution. This method has grown to include a number of options that may be specified for each outgoing command. disp = the display parser to associate with the outgoing command (None indicates that the standard viewer should be used). Setting prepend will instruct the command to be prepended to the queue - this causes the command to be the next command sent regardless of other waiting commands. preFlags/postFlags = the empQueue pre & post flags that should be requested for the command (assuming it is not a client-command). Setting raw will force this method to send the command unaltered - thus ignoring possible client-side commands. scommandNii(sdispsNonesviewersrawsselfs commandFormatsmatchscmdsmmsgroupsarg0sempParsesfindCmdspreListsfs syntaxListsistestspostListspreFlagspostFlagsempQueues NormalHandlershdlrsprependssocks AddHandler( sselfscmdsdispsprependspreFlagspostFlagsrawsmmsisfstestsarg0shdlr((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysSends>             cCs|d djo|id}|id=nI|d djov|d}t|}xtdt|iD]9}|i|}|| |jo|}|i|=PqlqlWtn|d djo|t i |dd}|djo tnt i |id|d|!||dd}||idjo tq@n|id=y|ii |Wntj onXd|g|id*d|_|id 3|i|d S( s7Send the command with support for history substitution.is!!is!s^iisidN(scmdsselfshisListslenslsrangesisvals IndexErrorsstringsfindspossreplacesremoves ValueErrorshisPossSend(sselfscmdsvalsislspos((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysHistSends@            cCs|djo|it|idjp|djo |idjo tn|djo |idjo||id/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysHistMove!sG cCs6|i|id||i|id|dS(sMulti-Command line.scmd1scmd2N(sselfsSendsmatchsgroupsout(sselfsmatchsout((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys SyntaxMulti+scCs|id}|djo d}n=|d djo d}n"|ddjo d }nd }|i|id t||id |d S(sRedirect output to a file.sflagss|spipeis>>sappendis!sforcesscmdsnameN(smatchsgroupsflagsstypesselfsSendsRedirectOutputsout(sselfsmatchsoutsflagsstype((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysSyntaxRedirect0s    (s__name__s __module__s__doc__s__init__s registerCmdssrescompiles commandFormatsNonesSendsHistSendsHistMoves SyntaxMultisSyntaxRedirect(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysEmpParses  ( 9 & s baseCommandcBsjtZdZdZeZZeZeZZ eZ eZ dZ e iZe iZeZeZdZRS(sBase class for synthetic commands. (Does little by itself.) This class is used as a base-class for creating new synthetic commands in the client. To define a new client-side command create a class that descends from this class, and then pass the new class to EmpParse.registerCmds(). The following class values are supported: description - a short text description that is printed when 'define' is called. commandFormat - if defined, it must be a regular expression that specifies the parameters for the command. commandUsage - a text string to print should the above regular expression fail to match. The following class attributes are not used by this base-class, but are used by EmpParse when the command is 'registered': defaultPreList - Sets the 'parse ordering' of the command. defaultBinding - A list of name/length pairs to bind the command to. The following methods are supported: invoke - Callback invoked the moment the user types the command. receive - Callback invoked when the outbound command queue reaches this command. sending - Callback invoked when the command queue is ready to send the command to the server. sNo help available.cCs||_||_|i|_||_|itj o|i d}| o d}n|ii||_ |i o?|i }|tjo|ii}ntid|dSqn|itj o|in|itj p |itj o|ii|ndS(Nsargsss'Invalid parameters. Form should be: %s(sdispsselfsoutsioqsSendsmatchs commandMatchs commandFormatsNonesgroupsargssparameterMatchs commandUsagesformspatternsviewersErrorsinvokesreceivessendingssocks AddHandler(sselfsioqsmatchsdispsformsargs((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys__init__ks&          cCsN|itj o:|ii}|ii||i|ii|ndS(s?EmpIOQueue Handler: Previous command completed; start this one.N( sselfsreceivesNones commandMatchsstringsssoutsBeginsEnd(sselfss((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysstarts   (s__name__s __module__s__doc__s descriptionsNonesdefaultPreListsdefaultBindings sendRefreshsinvokesreceives commandFormats commandUsages__init__sempQueuesQU_BURSTspreFlagss QU_FULLSYNCs postFlagsscommandssendingsstart(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys baseCommandAs      s CmdDefListcBs&tZdZddffZdZRS(NsList all online commands.sdefineicCs#|ii odSn|iidx:|iiD],\}}}|iid||ifq3W|iid|iidx<|ii D].}|iid|di |di fqW|iid|iidx:|ii D],\}}}|iid||ifqWdS( Ns Pre-syntax:s %-10s - %sssSyntax:s %-35s - %siis Post-syntax:( sselfsoutsdatasioqspreListsisksjs descriptions syntaxListspatterns__doc__spostList(sselfsisjsk((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceives  ! , (s__name__s __module__s descriptionsdefaultBindingsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys CmdDefListssCmdAliascBsPtZdZdZddffZeidZdZeidZ dZ RS( Ns)Generate a definition for a simple alias.isaliasis \$(\$|\*|\d+)salias s&^(?P\S+)\s+(?P.*?)\s*$cCs|iid}|iid}|ii|}dtfdY}dt ||_ |t |ff|_ ||_|ii|dS(NsvaluesnewNames dummyclasscBstZdZRS(NcCs|i}|iid}|tjo d}nti|ii}d}xt t |D]}||}|d@oy|djo||}q|djo|d}qy||t|}Wqtj otiddSqXq`||}q`W|i||iddS(s&Evaluate an alias for a given command.sargssis*s$sNot enough arguments for alias.N(sselfs substitutionsssublsts commandMatchsgroupsargssNonesstringssplitsarglscmdsrangeslenspartsvalsints IndexErrorsviewersErrorsSendsout(sselfscmdsvalssublstsargsspartsargl((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysinvokes,         (s__name__s __module__sinvoke(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys dummyclassss Aliased to (sselfsparameterMatchsgroupsnewcmdsnames EAliasFormatssplitslsts baseCommands dummyclasssreprs descriptionslensdefaultBindings substitutionssioqs registerCmds(sselfsnames dummyclassslstsnewcmd((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysinvokes ( s__name__s __module__s descriptionsdefaultPreListsdefaultBindingsrescompiles EAliasFormats commandUsages commandFormatsinvoke(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdAliasss CmdOrigincBs&tZdZddffZdZRS(Ns!Block unsupported server command.soriginicCstidtiddS(Ns+Sorry, the origin command is not supported.s*Please see TIPS.html for more information.(sviewersError(sself((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceives (s__name__s __module__s descriptionsdefaultBindingsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys CmdOriginssCmdRawcBs,tZdZdZddffZdZRS(Ns-Send a command without client interpretation.israwicCs&|ii|iiddddS(Nsargssrawi(sselfsioqsSends commandMatchsgroup(sself((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysinvokes(s__name__s __module__s descriptionsdefaultPreListsdefaultBindingsinvoke(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdRawssCmdBurstcBs,tZdZdZddffZdZRS(Ns8Send a multi-command line without syncing server output.isbursticCs|iid}| odSn|ii|iif\}}t i |i_|i_|i ||i ||f\|i_|i_dS(Nsargs( sselfs commandMatchsgroupsargssioqspreFlagspostFlagsprespostsempQueuesQU_BURSTsSendsout(sselfspresargsspost((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysinvokes(s__name__s __module__s descriptionsdefaultPreListsdefaultBindingsinvoke(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdBurstssCmdExeccBs/tZdZddfddffZdZRS(NsRun commands from a file.sexecuteisrunfeedicCs|iid}| odSnyC|iidd djoti|d}n t|}Wn(tj ot i d|dSnX|i }|i xP|D]H}ti|}| p|ddjoqn|i||iqWdS(NsargsscommandisrsUnable to open file [%s].is#(sselfs commandMatchsgroupsargssosspopensfilesopensIOErrorsviewersErrors readlinesslstsclosesisstringsstripsSendsout(sselfsargssislstsfile((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysinvoke s$   (s__name__s __module__s descriptionsdefaultBindingsinvoke(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdExecss SilentDispcBs;tZdZdZdZdZdZeiZ RS(s'Display class that discards most input.cCs tii||||_dS(N(sempParsesbaseDisps__init__sselfsdispsname(sselfsdispsname((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys__init__+scCs.|itijo|ii|indS(N(sselfsEndsempQueues doNothingsoutsname(sself((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys__del__.scCs:|itij o#|ii|iti|_ndS(N(sselfsBeginsempQueues doNothingsoutsname(sselfscmd((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysBegin1scCsti|_dS(N(sempQueues doNothingsselfsEnd(sselfscmd((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysEnd5s( s__name__s __module__s__doc__s__init__s__del__sBeginsEndsempQueues doNothingsdata(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys SilentDisp)s     sCmdNullcBs,tZdZdZddffZdZRS(NsRun command with no output.isnullicCs2|i|iidt|i|iidS(Nsargs(sselfsSends commandMatchsgroups SilentDispsoutsstring(sself((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysinvoke@s(s__name__s __module__s descriptionsdefaultPreListsdefaultBindingsinvoke(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdNull9ss CmdPredictcBs,tZdZdZddffZdZRS(NsGet predictions for a sector.sesPredicticCsyti|iid}Wn$tj otiddSnXt i d|}x3t i ti|dD]}|ii|qsWdS(NsargssInvalid coordinates.sSECTORs (sempParses str2Coordssselfs commandMatchsgroupscoords ValueErrorsviewersErrorsempDbsmegaDBsDBsstringssplits empSectorssectorPredictionssisoutsdata(sselfsDBscoordsi((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceiveLs  (s__name__s __module__s descriptions sendRefreshsdefaultBindingsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys CmdPredictEssCmdMovercBsAtZdZdZddffZdZeidZdZ RS(NsIssue a multi-stage move.sesMoveris=Mover [ ...]s6^(?P\S+)\s+(?P[+-@]?\d+)\s+(?P.*)$c CsI|i}yvttiti|id}t |djo t nt i |id}t|id||}Wn&t tfj otidnX|djo| }|inxxtt |dddD]Z}||d}||}|id ||d|d||d|df|idqWdS( NssectorsiscomdsvalsMove invalid input failure.iiismove %s %d,%d %d %d,%d(sselfsparameterMatchsmmsmapsempParses str2Coordssstringssplitsgroupssectorsslens ValueErrorsempEvalscommodityTransforms commoditysgetMoveQuantitysquantitysKeyErrorsviewersErrorsreversesrangesislastscursSendsout(sselfslastssectorssmms commodityscursisquantity((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceive`s&     /( s__name__s __module__s descriptions sendRefreshsdefaultBindings commandUsagesrescompiles commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdMoverVs s CmdRefreshcBstZdZddfddffZeidZeiZ ddd fd d d fd ddfdddfdddfdddfgZ dZ dZ dZ RS(NsRefresh client databases.srdbisrerdbis2^(?Pre)?rdb(?P
P)?(?P[eslpno]*)$sesSECTORsdumpsls
LAND UNITSsldumpsssSHIPSssdumpspsPLANESspdumpsnsNUKESsndumpsos
LOST ITEMSslostcCs|ii|iid}|otiddSnt|i|i	|_|idpd|_
|idtj|_|idtj|_
d|_dS(Nscommandsrefresh regex failure.sflagsselsposprestotals(sselfs
syncFormatsmatchscommandMatchsgroupsviewersErrors
SilentDispsoutsstringsdumpListsNones
persistents	totalDumps
neededDump(sselfsmatch((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysinvokes
cCs|itj	o@x5|iD]*}||ijo|i||_qqWdSn|i|ijox|iD]z}ti	|i|}|djoti	|i|djo6|i| |i|d|_|iodSqqmqmWndSdS(s6empQueue scan callback: Don't send redundant commands.iiiN(sqElemssendRefreshsNonesisselfs
neededDumps	__class__sdumpListsstringsfindspos(sselfsqElemsispos((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pyscheckPendings 

)c	Csx|iii}|io$|iii|id|dnx|iD]}|d|i
joqHnd}|io|ddjo3t
i|di}|djod|}qn|d}|iiiti|dd||id	tid
tid|qHW|iodt
id
djo>|iiitid|id	tid
tid|ndS(Nsstartiissns ?timestamp>%sis *sprespostsposs
MOB_ACCESSsversionsenabledOptionss
dump * mob(sselfsioqssocks	FLSentLevsqPoss
persistents	scanQueuescheckPendingscommandFlagssdumpInfosdumpListstss	totalDumpsempDbsmegaDBsunofficial_timestampstimes
AddHandlersempQueues
NormalHandlersoutsQU_SYNCs
QU_FORCEBURST(sselfsqPossdumpInfostsstime((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pyssendings($


0#$(s__name__s
__module__sdescriptionsdefaultBindingsrescompiles
syncFormatsempQueuesQU_BURSTs	postFlagsscommandFlagssinvokescheckPendingssending(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys
CmdRefreshws	N		s(?P\w+)s(?P\w+)s(?P.*)sCmdEvalcBsZtZdZdZdZddffZdZeide	i
ded	Zd
Z
RS(Ns-Evaluate an expression for a sector/database.seisevalis,eval {|'nation'|'version'} s
^(?Ps|nation|version)\s+s$cCs
|i}|id}|djp
|djoti|}ndd}tt	t
|idd}ytid|}Wn$tj
ot
iddSnXy;|ititi|id|||id	Wn%tij
o}t
i|nXdS(
NstypesnationsversionsSECTORssectorXssectorYsCould not find sector.scommandi(sselfsparameterMatchsmmsgroupstypesempDbsmegaDBsdbstuplesmapsintskeysKeyErrorsviewersErrorsSendsempEvals
evalStrings
estrToExprsoutserrorse(sselfsesmmsdbskeystype((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceives"	!
	!	(s__name__s
__module__sdescriptionssendRefreshsdefaultPreListsdefaultBindingscommandUsagesrescompilesempParsess_sectors	s_commands
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdEvals"s
CmdForEachcBsOtZdZdZdZddffZdZeide	dZ
d	ZRS(
Ns'Run given command on specified sectors.seisforeachis*foreach  [?] s0^(?P\S+)\s+(?:\?(?P\S+)\s+)?s$cCs|i}yPtidtid|id|idti|idd}Wn%ti	j
o}ti|n)Xx$|D]}|i||idqWdS(Nsowner==-1 and sSECTORssectorss	selectorsscommandi(sselfsparameterMatchsmmsempEvalsforeachsselectToExprsgroups
estrToExprslistserrorsesviewersErrorsisSendsout(sselfsesismmslist((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceives	
(s__name__s
__module__sdescriptionssendRefreshsdefaultPreListsdefaultBindingscommandUsagesrescompiles	s_commands
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys
CmdForEachssCmdOutcBs,tZdZdZddffZdZRS(Ns Debugging tool - dumps database.sespnlosouticCs|iittidS(N(sselfsoutsdatasstrsempDbsmegaDB(sself((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceives(s__name__s
__module__sdescriptionssendRefreshsdefaultBindingsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdOutssCmdMMovecBsLtZdZdZddffZdZeidei	dZ
dZRS(	NsUlf Larsson's multi-move tool.sesmmoveisOmmove      s^s\s+(?P\S+)(?:\s+\?(?P\S+))?\s+(?P\S+)\s+(?P\S+)\s+(?P\S+)(?:\s+\?(?P\S+))?\s+(?P\S+)\s*$c	Cs|i}|idddd\}
}}}
yti	|
}
Wn$t
j
otiddSnXyti
dtid|id|id	d
|
d|d|d
d}ti
dtid|id|idd|
d|
dd}Wn)tij
o}ti|dSnXh}xE|D]=\}}}|djoti||
o|||q>Wh}	x{|D]s\}}}}|djo.|djo!|i|oti||
o#||ti||
f|	|/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceive;sH	$
		

	 >';
(s__name__s
__module__sdescriptionssendRefreshsdefaultBindingscommandUsagesrescompilesempParsess_comms
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdMMove,ssCmdEMovecBsLtZdZdZddffZdZeidei	dZ
dZRS(	Ns&Ulf Larsson's multi-move explore tool.sesemoveisJemove {civ|mil}    s^s\s+(?P\S+)(?:\s+\?(?P\S+))?\s+(?P\S+)\s+(?P\S+)\s+(?P\S+)(?:\s+\?(?P\S+))?\s*$cCsc|i}
|
iddd\}}}yti|}Wn$t	j
ot
iddSnXytid|dti
d|
id|
id	d
|d|d|d
d}titi
d|
id|
iddd}Wn)tij
o}t
i|dSnXh}
x2|D]*\}}ti|od|
|0 and sSECTORssectorss	selectorss(xloc+0,yloc+0), __db[1], int(s-(s
)), int(mob-(s))ssectors2s
selectors2s(xloc+0,yloc+0), __db[1]iif1.0sexplore %s %d,%d %s %sh()sselfsparameterMatchsmmsgroups	commoditysslevelsmobsempEvalscommodityTransformsKeyErrorsviewersErrorsforeachsselectToExprsslistsdlistserrorsesddictscoordsdbs	empSectorsis_explorable_intossdictsamountsmobilityshas_keysis_movable_fromsempPaths
MoveGeneratorsExplMobCostsmmovesemptysmovescommspathsSendsstarts
directionssoutsnext(sselfsslistsmobilitysmobsdlistsslevelsdbscommspathssdictsddictses	commoditysmmscoordsmmovesamount((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceivesJ	
		

	>-
(s__name__s
__module__sdescriptionssendRefreshsdefaultBindingscommandUsagesrescompilesempParsess_comms
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdEMoveussCmdNovacBsbtZdZdZddffZdZeidei	dei
deid	Zd
Z
RS(NsAuto-explore sectors.sesnovais*nova {civ|mil}  []s^s\s+s\s*(?:s)?\s*$cCs|i}tt|idd}|idott|idd}n|}||jodt|}ndt||}t
id}t
i
}	xt
i|D]|}|i|h}
|
id}|
id	}|d
jp|tjp
||	jo|tj	o
|djoPqqWdS|id|id
d|t|i|i|id
||dtiti|id|idtidS(NssectorXssectorYssector2Xssector2Ys%s,%s 1s
%s,%s 1 %s,%ssSECTORsdessowneris.?s\sexplore scomms isdes * ?newdes=-&mob<1 +spostFlag(sselfsparameterMatchsmmsmapsintsgroupsstartsdeststuplesestrsempDbsmegaDBsdbs
CN_UNOWNEDssectorNeighborssnewcoordsgetssectsdessownsNonesSends
HandleNovasoutsioqsempQueuesQU_SYNCsQU_FULLSYNCs
QU_FORCEBURST(sselfsownsmmsnewcoordsdessdbsdestsstartsestrs
CN_UNOWNEDssect((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceives.	

	A	$(s__name__s
__module__sdescriptionssendRefreshsdefaultBindingscommandUsagesrescompilesempParsess_commss_sectors	s_sector2s
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdNovas0s
HandleNovacBsAtZdZdZeiiZdZeiiZdZ	RS(sParse class for nova handled explores.

    This class receives output after the empParse.ParseMove class.
    Basically, it automatically generates moves based on the information
    contained in the prompts.
    cCsMtii||||_||_||_||_t	|_
d|_dS(Ni(sempParsesbaseDisps__init__sselfsdispsslfscomdsstartsdestsNonesoldflushsdirec(sselfsdispsslfscomdsstartsdest((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys__init__s					cCs|ii|}|o|ii||dSn|it	j	o
||ijo%|ii|t	|ddSn||_t
id}t
i
}
t
i|i}t
i}	xno|it|	jo%|ii|t	|ddSn||i}|i|h}|id}|id}|djp
|t	jo|t	j	o
|djp||
jo
|djo)|ii|t	||	|iPn|id|_qW|id|_dS(	NshsSECTORisdessowneris.\s?s(sselfspromptFormatsmatchsmsgsmmsoutsflushshdlsoldflushsNonesempDbsmegaDBsdbs
CN_UNOWNEDssectorNeighborssdests	neighborsspathDirectionssdirecslensnewcoordsgetssectsdessown(sselfsmsgshdls	neighborssownsmmsnewcoordsdessdbspathDirectionss
CN_UNOWNEDssect((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysflushs: 
	
		

Nc
Cs|ii||ii|}|o|itt	i
joXt|it
iid|i|id|id|id|idf|in|iid|i|id|id|id|idf|indS(Nsnova %s %s,%s %s,%siissectorXssectorY(sselfsoutsdatasmsgs	ownSectorsmatchsmmsdirecslensempDbspathDirectionssCmdNovasslfsEmpParses
commandFormatscomdsstartsdestsSendsgroup(sselfsmsgsmm((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysdata s	AB(
s__name__s
__module__s__doc__s__init__sempParses	ParseMovespromptFormatsflushs	ownSectorsdata(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys
HandleNovas		#s	ParseShowcBs2tZdZdZdZdZdZRS(sRearrange output from multiple commands into a set of columns.

    This is a hack!  - It is really only usefull for show XXX YYY.
    Now this hack got hacked by Bernhard to let capability listings
        not grow to big. So it is special for cshow. :-)
        It is important that "cap" are the last char of the last command
        which this class is called with.

    Kevin has arranged a list Body. The last element is printed first,
    so that commands with more overhead lines can append to the list.
    cCs;tii||g|_g|_d|_d|_dS(Nii(	sempParsesbaseDisps__init__sselfsdispsCBodysBodysfirstsfoundheader(sselfsdisp((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys__init__[s
			cCsCx<tdt|idD]}|ii|i|qWdS(Ni(srangeslensselfsBodysisoutsdata(sselfsi((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys__del__cscCs|ii||iottt|i}nd}|ddjod|d}nd}xqtt|iD]Z}|ddjoxt|i||jot|i|}||||jo||d|}n|||}|ii||d|d|i|||i|| |i|<|d}qWn|dt|ijo#|iid||i|q{|i||d|t|i|||i||i||/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysEndhs4
.#H			cCsv|io/ti|d djo
d|_q:dSn|io|g|idd+n|dg|idd+dS(Nisii(sselfsfoundheadersstringslstripsmsgsfirstsCBody(sselfsmsg((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysdatas

(s__name__s
__module__s__doc__s__init__s__del__sEndsdata(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys	ParseShowNs
			*sRedirectOutputcBs2tZdZdZdZdZdZRS(s(Redirect a command to a file or program.cCs)tii||||_||_dS(N(sempParsesbaseDisps__init__sselfsdispsnamestype(sselfsdispsnamestype((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys__init__s	cCs|iitijodSn|ii|y|idjoti|i	d|_
np|idjo
d}nA|idjotii
|i	otd|i	nd}t|i	||_
Wn1tidttid t|_
nXdS(	NspipeswsappendsasforcesFile %s already exists.sException %s with detail:
"%s".i(sselfsoutsBeginsempQueues	doNothingscmdstypesosspopensnamesfilesflagsspathsexistssIOErrorsopensviewersErrorstuplessyssexc_infosNone(sselfscmdsflags((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysBegins
&!cCs5|ii||itj	o|iindS(N(sselfsoutsEndscmdsfilesNonesclose(sselfscmd((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysEndscCs<|itj	o|ii|dn|ii|dS(Ns
(sselfsfilesNoneswritesmsgsoutsdata(sselfsmsg((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysdatas(s__name__s
__module__s__doc__s__init__sBeginsEndsdata(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysRedirectOutputs
			cCsti|}d}|o|ddjo/|ddjod}|d}q\d}nt|}|djo
|}nh|djo/ti	d|d}||i|d}n,ti	d|d}|i|d|}|SdS(Nis-+@s@iisSECTORi(sstringslstripstxtsvarsflagsintsvalsquantitysempDbsmegaDBssectorssdbsgets	commodity(stxts	commodityssectorssquantitysdbsflagsvalsvar((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysgetMoveQuantitys 



cCswtiti|d}|odSnd}ti}tii	}||d|x|o|d}|d=|ddddfjo|d	}nt|}|d
jo0d
|}|d i||d|| }nN||d
jo<|dd|d|dd
||d|d|d}n||d|d|dd
||d
}qYW|dd|dd
dS(sSend a telegram to the server.

    This function takes a telegram/announcement command stored in cmd, and
    a multi-line string stored in msg and then bursts the telegram command
    and the body of the message to the server.  The results of this command
    are not synchronized or checked in any way.  Assumptions are made about
    the form and acceptable content of a telegram, and then all the info is
    bursted out.  The advantage of bursting telegrams, is that it makes the
    transmission extremely fast.
    s
NispostFlags~us~ps~qs.s ispreFlagsrawi(sstringssplitsrstripsmsgstotsempQueuesQU_BURSTsviewersioqsSendscmdsvalslenslsinsert(scmdsmsgsvalsQU_BURSTslstotsSend((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pyssendTelegrams4
	



s	CmdRemovecBsAtZdZdZddffZdZeidZdZ	RS(Ns3Remove a unit (ship, land, plane) from the databaseisremoveis&remove {s|l|p}  []sF^(?P[slp])\s+(?P\S+)(?:\s+\?(?P\S+))?\s*$|^$c
Csy|i}|iddd\}}}|tjoti	ddSn|tjoti	ddSn|iddjo
d}nA|iddjo
d	}n!|idd
jo
d}ny;tidti
d
|id|id|}Wn%tij
o}ti	|nIXxD|D]<}	|	d}ti|ihd|<dti/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceive2s2	








(
s__name__s
__module__sdescriptionsdefaultPreListsdefaultBindingscommandUsagesrescompiles
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys	CmdRemove'ssCmdDannocBs,tZdZdZddffZdZRS(Ns-Dump all annoucements to the screen or a fileisdannoicCstidi}tidi}xtiddD]}t|dtijo[d|dd|ddtj	od||ddpd	||dd
f}n|d}|ii|x"|dD]}|ii|qW|iidq2WdS(Nstimes	countriess
announcementsslistis> %s%s  dated %sis from %ssis
(sempDbsmegaDBs	printTimesgetNamesmstypestypess	TupleTypesNoneshdrsselfsoutsdatasl(sselfshdrs	printTimesmslsgetName((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceiveWs[
(s__name__s
__module__sdescriptionsdefaultPrelistsdefaultBindingsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdDannoQssCmdDtelecBs,tZdZdZddffZdZRS(Ns*Dump all telegrams to the screen or a fileisdteleicCstidi}tidi}xtiddD]}t|dtijo[d|dd|ddtj	od||ddpd	||dd
f}n|d}|ii|x"|dD]}|ii|qW|iidq2WdS(Nstimes	countriess	telegramsslistis> %s%s  dated %sis from %ssis
(sempDbsmegaDBs	printTimesgetNamesmstypestypess	TupleTypesNoneshdrsselfsoutsdatasl(sselfshdrs	printTimesmslsgetName((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceivems[
(s__name__s
__module__sdescriptionsdefaultPrelistsdefaultBindingsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdDtelegss
CmdProjectioncBs2tZdZdZdZddffZdZRS(Ns(Computes the new efficiency of all unitssespnlois
projectionic	Cs_dddddddffdd	d
dddffddd
ddddffg}|iid|iidx|D]}ti|d}}h}|i	}|ix|D]}
||
}|dtijoqny|d}Wn4tj
o(|ddjo
d}q)d}nX|djoqn|d|df}ytid|}Wntj
o
qnX|d|djoqnx|dD]}|i|oh|||iid$|
d|
d||
|||fd}	qqW|	djo&|iid%|
d|
dfqqWq{WdS(&NsPLANESs	planetypes*slcmshcmsmilsavailsSHIPSsshiptypeshs
LAND UNITSslandtypes!sgunsBuilding Projectionss====================isownerseffii
idsxsysSECTORsdesiif0.0istypesYou should issue a 'show is& build' command to update the databasef100.0sSector %d,%d needs %.0f more %ssSector %d,%d is ok.(s
conversionsselfsoutsdatastypsempDbsmegaDBsdbs
needed_comskeysslstssortsidsunitsCN_OWNEDsesKeyErrorscoordssectscshas_keysneededsviewersErrorsssoksstock(sselfs
conversionsescssectsdbscoordsneededslstsoksssstockstypsidsunits
needed_com((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceiveshT



! .
4
(s__name__s
__module__sdescriptionssendRefreshsdefaultPrelistsdefaultBindingsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys
CmdProjection}s
sCmdDmovecBsFtZdZddffZdZeideidZ	dZ
RS(Nsesdmoveis@dmove    [zero] []s^s\s+(?P\S+)(?:\s+\?(?P\S+))?\s+(?P\S+)(?:\s+(?Pz|ze|zer|zero))?(?:\s+(?P\S+)(?:\s+\?(?P\S+))?)?\s*$c	Cs|i}|idd\}
}yti|
}
Wn$tj
ot	i
ddSnX|ido
d}nd}|id}	|id}|	tjo"|id	}	|id
}nytid|
d|
d
d|
d
d|dtid|id	|id
d|
d|
d
d|dd}tidtid|	|d|
d
d|
dd}Wn)tij
o}t	i
|dSnXh}xE|D]=\}}}|d
joti||
o|||is
_dist and s_dist>s and sSECTORs(xloc+0,yloc+0), __db[1], int(s-(s_dist)), int(mob-(s))s(xloc+0,yloc+0), __db[1], int((s_dist)-s)smove %s %d,%d %s %d,%di(,sselfsparameterMatchsmmsgroups	commoditysmobsempEvalscommodityTransformsKeyErrorsviewersErrorsminComssectors2s
selectors2sNonesforeachsselectToExprsslistsdlistserrorsesddictscoordsdbsamounts	empSectorsis_movable_intossdictsmobilityshas_keysis_movable_fromsmove_weightsempPaths
MoveGeneratorsmmovesemptysmovescommspathsSendsstartsendsoutsnext(sselfsslistsmobilitys
selectors2smobsdlistsdbsminComscommssectors2ssdictsddictses	commoditysmmscoordsmmovesamountspath((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceivesX	
	

:	


	 >';
(s__name__s
__module__ssendRefreshsdefaultBindingscommandUsagesrescompilesempParsess_comms
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdDmoves
s
CmdSetFoodcBsStZdZdZdZddffZdZeiddd	d
Z	dZ
RS(Ns1Set food thresholds for maximum population growthseissetfoodissetfood  [no] [force]s,(?P\S+)(?:\s+\?(?P\S+))?s(?:\s+(?Pno))?s(?:\s+(?Pforce))?s\s*$cCs|i}y;tidtid|id|idd}Wn)tij
o}t
i|dSnX|ido
d}
nd}
|ido
d}	nd}	x|D]}tid|}tti|}|	djo
|}n&||d	jo
|}n|d	}|
djo||d	/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceive,s:	

	






(s__name__s
__module__sdescriptionssendRefreshsdefaultPrelistsdefaultBindingscommandUsagesrescompiles
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys
CmdSetFoodssCmdLTestcBsKtZdZdZdZddffZdZeiddZ	d	Z
RS(
NsQCompute the amount of mobility a land unit would
    use to reach a given sector.selisltestisltest  s(?P\d+)\s+s(?P-?\d+),(?P-?\d+)cCs^|i}|tjodSnt|id}ytid|f}
Wn(t
j
otid|dSnX|
d|
df}t|idt|idf}	||	jo(|iid|iid	dSn|iid
|	ti||	}|tjotiddSnd}x|iD]}||}qAW|iid
||if|idd|
d|
dd|
dd|
d}titid|	}|dd|
d|
dd|
dd|
d}|||
djo|iidn7t|
d|}|iid|
d||fdS(NslandIds
LAND UNITSsLand unit %d doesn't exist.sxsysxLocsyLocs(Using best path 'h', movement cost 0.000sTotal movement cost cost: 0sLooking for best path to %d,%dsPath could not be completed.ss(Using best path '%s', movement cost %.3ff5.0f480.0sspdf50.0stechf200.0sSECTORsmobs&Not enough mobility to go all the way.s$Total movement cost: %d, new mob: %d(sselfsparameterMatchsmmsNonesintsgroupslandIdsempDbsmegaDBsunitsKeyErrorsviewersErrorsfromLocstoLocsoutsdatasempPaths	best_pathspathsss
directionssiscostsmcosts	empSectorsmob_costs	last_stepsnewmob(sselfs	last_stepsfromLocsmmsnewmobslandIdspathsssistoLocsunitsmcost((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysreceive]s@	
	*



96(s__name__s
__module__sdescriptionssendRefreshsdefaultPreListsdefaultBindingscommandUsagesrescompiles
commandFormatsreceive(((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pysCmdLTestQs(0s__doc__ssyssossstringsresbisectstypessempQueuesempDbsempParsesempEvalsempPaths	empSectorsEmpParsesbaseCommands
CmdDefListsCmdAliass	CmdOriginsCmdRawsCmdBurstsCmdExecsbaseDisps
SilentDispsCmdNulls
CmdPredictsCmdMovers
CmdRefreshss_varss_vals	s_commandsCmdEvals
CmdForEachsCmdOutsCmdMMovesCmdEMovesCmdNovas
HandleNovas	ParseShowsRedirectOutputsgetMoveQuantityssendTelegrams	CmdRemovesCmdDannosCmdDteles
CmdProjectionsCmdDmoves
CmdSetFoodsCmdLTest(.sCmdDmoves	CmdOrigins
CmdProjectionsbaseCommandss_valss_varsCmdEMovesempDbsRedirectOutputsCmdLTestsCmdMovers
CmdForEachsCmdOutsCmdAliass	empSectors
SilentDispsempPathssendTelegramsempQueuesCmdNullsresCmdNovasCmdMMovesCmdDtelesstringsCmdRawsempParsessyssCmdBurstsempEvalsCmdExecstypess	ParseShowsCmdDannosgetMoveQuantitysbisectsCmdEvals
CmdSetFoodsEmpParses	s_commands
HandleNovas
CmdDefLists	CmdRemoves
CmdRefreshsoss
CmdPredict((s>/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empCmd.pys?s\												aX2		$!V !II-cP'	:	(*MT3