
b]c           @  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d   Z d   Z i  Z d   Z	 e	 d    Z
 e	 d    Z e j j d  Z d	   Z d
   Z d   Z i- e e f d 6e d 6e d 6e e f d 6e d 6e d 6e d 6e d 6e d 6e d 6e e f d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d  6e d! 6e e f d" 6e e f d# 6e d$ 6e d% 6e e e e f d& 6e d' 6e e f d( 6e e f d) 6e e f d* 6e e f d+ 6e d, 6e d- 6e d. 6e d/ 6e e f d0 6e d1 6e d2 6e d3 6e d4 6e d5 6e d6 6e d7 6e d8 6Z d9   Z d:   Z d;   Z g  a d<   Z d= e f d>     YZ d? e j j f d@     YZ e j j   j  Z  e j j! Z! dA e f dB     YZ" dC e j j f dD     YZ# dE e" f dF     YZ$ dG e# f dH     YZ% dI e" f dJ     YZ& dK e" f dL     YZ' dM e" f dN     YZ( dO e# f dP     YZ) dQ e# f dR     YZ* dS e" f dT     YZ+ dU e# f dV     YZ, dW e" f dX     YZ- dY e# f dZ     YZ. d[ e" f d\     YZ/ d] e# f d^     YZ0 d_ e" f d`     YZ1 da e# f db     YZ2 dc e" f dd     YZ3 de e# f df     YZ4 dg e" f dh     YZ5 di e# f dj     YZ6 dk e" f dl     YZ7 dm e# f dn     YZ8 do   Z9 d S(p   i(   t   print_functionNc         C  s&   |  \ } } d | | f t  j _ d  S(   Ns   Compiling ATL code at %s:%d(   t   renpyt   gamet   exception_info(   t   loct   filet   number(    (    s   renpy/atl.pyt	   compiling   s    c         C  s&   |  \ } } d | | f t  j _ d  S(   Ns   Executing ATL code at %s:%d(   R   R   R   (   R   R   R   (    (    s   renpy/atl.pyt	   executing$   s    c         C  s   |  j  } |  t | <|  S(   N(   t	   func_namet   warpers(   t   ft   name(    (    s   renpy/atl.pyt
   atl_warper.   s    	
c         C  s   |  d k  r d Sd Sd  S(   Ng      ?g        (    (   t   t(    (    s   renpy/atl.pyt   pause7   s    c         C  s   d S(   Ng      ?(    (   R   (    (    s   renpy/atl.pyt   instant?   s    t   positionc         C  s   |  S(   N(    (   t   x(    (    s   renpy/atl.pyt
   any_objectG   s    c         C  s   |  d  k r |  St |   S(   N(   t   Nonet   bool(   R   (    (    s   renpy/atl.pyt   bool_or_noneK   s    c         C  s   |  d  k r |  St |   S(   N(   R   t   float(   R   (    (    s   renpy/atl.pyt   float_or_noneQ   s    t   post   xpost   ypost   anchort   xanchort   yanchort   xaroundt   yaroundt   xanchoraroundt   yanchoraroundt   alignt   xalignt   yalignt   rotatet
   rotate_padt   transform_anchort   xzoomt   yzoomt   zoomt   nearestt   alphat   additivet   aroundt   alignaroundt   anglet   radiust   cropt   crop_relativet   sizet   maxsizet   corner1t   corner2t   subpixelt   delayt   xoffsett   yoffsett   offsett   xcentert   ycentert   debugt   eventst   xpant   ypant   xtilet   ytilec         C  s=   | t  k r/ |  d k r d St |  |   Sn
 | |   Sd S(   sL   
    Corrects the type of v to match ty. b is used to inform the match.
    N(   R   R   t   type(   t   vt   bt   ty(    (    s   renpy/atl.pyt   correct_type   s
    c           s   t  | t  rW | d k r1 d g t |  } n  t   f d   t | | |  D  S| d k sx t  | t t f  r   d k r | S| Sn1 | d k r d } n  t |   | | | |  Sd S(   s-   
    Linearly interpolate the arguments.
    c         3  s-   |  ]# \ } } } t    | | |  Vq d  S(   N(   t   interpolate(   t   .0t   it   jRI   (   R   (    s   renpy/atl.pys	   <genexpr>   s    g      ?i    N(   t
   isinstancet   tupleR   t   lent   zipR   t
   basestringRJ   (   R   t   aRH   RF   (    (   R   s   renpy/atl.pyRK      s    &!	c           s  t  | d t  r3 t   f d   t |   D  S| d d  k rK | d St |  d k r d   } | | d   | d } nt |  d k r d   d } d   d   }   d } | | d | | d | | d } n t |  d k rtd   d } d   d   d } d   d d   }   d } | | d | | d | | d | | d } n t d	 t |    t | | d t  S(
   Nic         3  s   |  ] } t    |  Vq d  S(   N(   t   interpolate_spline(   RL   RM   (   R   (    s   renpy/atl.pys	   <genexpr>   s    i    i   g      ?i   i   i   s+   ATL can't interpolate splines of length %d.(   RO   RP   RR   R   RQ   t	   ExceptionRJ   R   (   R   t   splinet   t_pt   rvt   t_ppt   t2t   t_pppt   t3(    (   R   s   renpy/atl.pyRU      s(     

)
5c          C  s:   x- t  D]% }  |  j j t k r |  j   q q Wg  a  d S(   sm   
    Called after the init phase is finished and transforms are compiled,
    to compile all transforms.
    N(   t   compile_queuet   atlt   constantt   GLOBAL_CONSTt   compile(   RM   (    (    s   renpy/atl.pyt   compile_all   s    t   Contextc           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s   | |  _  d  S(   N(   t   context(   t   selfRe   (    (    s   renpy/atl.pyt   __init__   s    c         C  s+   t  j j |  } t | t  j j |  j  S(   N(   R   t   pythont   escape_unicodet   evalt   storet   __dict__Re   (   Rf   t   expr(    (    s   renpy/atl.pyRj      s    c         C  s#   t  | t  s t S|  j | j k S(   N(   RO   Rd   t   FalseRe   (   Rf   t   other(    (    s   renpy/atl.pyt   __eq__   s    c         C  s   |  | k S(   N(    (   Rf   Ro   (    (    s   renpy/atl.pyt   __ne__   s    (   t   __name__t
   __module__Rg   Rj   Rp   Rq   (    (    (    s   renpy/atl.pyRd      s   			t   ATLTransformBasec           B  s   e  Z e j j g  g  d d  Z d Z d  Z d Z	 d g Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d	   Z d
   Z RS(   i    t   parent_transformc         C  s   | d  k r t j } n  | |  _ | |  _ t |  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 t
 |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d |  _ t j j   j r t j |   n  d  S(   Ni    (   R   Rt   t
   parametersR_   Rd   Re   t   blockt   predict_blockt
   propertiest	   atl_stateRn   t   donet   transform_eventt   last_transform_eventt   last_child_transform_eventt	   raw_childRu   t   atl_st_offsetR   R   t
   init_phaseR^   t   append(   Rf   R_   Re   Rv   (    (    s   renpy/atl.pyRg     s$    													c         C  sH   |  j  d  k	 r% |  j  j |  r% t S|  j d  k r8 t S|  j j |  S(   N(   Rw   R   t   _handles_eventt   Truet   childRn   (   Rf   t   event(    (    s   renpy/atl.pyR   J  s
    !c         C  s7   |  j  r |  j  S|  j r/ t j j j r/ |  j Sd Sd S(   s4   
        Returns the compiled block to use.
        N(   Rw   Rx   R   t   displayt   predictt
   predictingR   (   Rf   (    (    s   renpy/atl.pyt	   get_blockS  s
    	c         C  sd  t  t |   j |  d |  _ |  | k r/ d St | t  sB d S| j |  j k	 rX d Sy | j |  j k sq d SWn n X| j |  _ | j	 |  _	 | j
 |  _
 | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ |  j t j j j k r`| j rE| j j rE| j j d  |  _ n | j |  _ | j |  _ n  d S(   sy   
        Updates self to begin executing from the same point as t. This
        requires that t.atl is self.atl.
        N(   t   superRt   t   take_execution_stateR   R   RO   R_   Re   R{   Rw   Rz   R|   R}   R~   t   stt   att	   st_offsett	   at_offsetR   R   R   t   motiont   nullt   _duplicatablet
   _duplicateR   (   Rf   R   (    (    s   renpy/atl.pyR   _  s:    	c         O  s"  | j  d d   } |  j j j   } x? |  j j D]1 \ } } | d  k	 r1 t j j |  | | <q1 q1 Wt |  j j	  } t |  } d  } | r | r | j  d  } n  xW | r| r| j  d  }	 | j  d  }
 |	 | k r t
 d |	   n  |
 | |	 <q W| rt
 d   n  x~ | j   D]p \ } } | | k rW| j |  | | | <q%| | k rp| | | <q%| d k r| } q%t
 d |   q%W| d  k r|  j } n  t j j i  | d  d   } t j j j d |  j d | d |  j d	 | d
 | d |  } |  | _ | j |   | S(   Nt   _argsi    sO   Parameter %r is used as both a positional and keyword argument to a transition.s+   Too many arguments passed to ATL transform.R   s+   Parameter %r is not known by ATL Transform.R_   t   styleRe   Rv   (   t   popR   Re   t   copyRv   R   Rh   t   py_evalt   listt
   positionalRV   t	   iteritemst   removeR   t   astt   ParameterInfoR   R   t   ATLTransformR_   t	   style_argRu   t
   take_state(   Rf   t   argst   kwargsR   Re   t   kRG   R   R   R   t   valueRv   RY   (    (    s   renpy/atl.pyt   __call__  sP    					c         C  s  |  j  j t k } | s~ xc |  j j D]R } | |  j j k r% t d |  j  j d |  j  j d |  j j d f   q% q% Wn  | r |  j r |  j j	 r |  j j	 |  _	 |  j j
 |  _
 d |  _ |  j	 Sn  t j j } |  j  j |  j  } t d   | j D  r7g  |  _
 x' | j D] } |  j
 j | j
  qWn  | rYt j j j rY| |  _ n | |  _	 d |  _ | t j _ | r|  j r|  j	 |  j _	 |  j
 |  j _
 d |  _ n  | S(   sc   
        Compiles the ATL code into a block. As necessary, updates the
        properties.
        sO   Cannot compile ATL Transform at %s:%d, as it's missing positional parameter %s.i    i   c         s  s-   |  ]# } t  | t  o$ | j d  k Vq d S(   i    N(   RO   t   Interpolationt   duration(   RL   t	   statement(    (    s   renpy/atl.pys	   <genexpr>  s   N(   R_   R`   Ra   Rv   R   Re   RV   R   Ru   Rw   Ry   R   R   R   R   Rb   t   allt
   statementst   extendR   R   R   Rx   (   Rf   R`   t   pt   old_exception_infoRw   t   interp(    (    s   renpy/atl.pyRb     s@    !	
			c         C  s  |  j  r d  S|  j   } | d  k r4 |  j   } n  g  } | j rO d |  _ n  | j rd d |  _ n  t j j	 r |  j |  j
 k r | j |  j  |  j |  _
 q n  |  j d  k	 r |  j j |  j k r |  j j |  _ |  j j d  k	 r |  j j |  _ q n  |  j |  j
 k r/| j |  j  |  j |  _
 n  |  j t j j k rYd  |  _ d  |  _
 n  t j j } |  j d  k s| |  j d k  r| |  _ n  |  j j r| } n | |  j } | j | | |  j |  \ } }	 }
 | t j _ | d k rt j j j r|	 |  _ n	 t |  _  |
 S(   Nt   hidet   replacedi    t   continue(   R{   R   R   Rb   t   hide_requestR|   t   replaced_requestR   t   configt   atl_multiple_eventsR}   R   R   R~   t   repeat_transform_eventsR   R   R   R_   t	   animationt   executeRz   R   R   R   R   (   Rf   t   transR   R   Rw   RA   R   t   timebaset   actiont   argR   (    (    s   renpy/atl.pyR     sH    			$	"	$	c         C  s   |  j  j |  j  d  S(   N(   R_   R   Re   (   Rf   (    (    s   renpy/atl.pyt   predict_one?  s    c         C  s8   |  j    } | d  k r' |  j   } n  |  j | j   S(   N(   R   R   Rb   t   childrent   visit(   Rf   Rw   (    (    s   renpy/atl.pyR   B  s    N(   Rr   Rs   R   R   R   R   Rv   Ru   R   Rx   t   nosaveRg   R   R   R   R   Rb   R   R   R   (    (    (    s   renpy/atl.pyRt     s   		8				0	@	3	=	t   RawStatementc           B  s2   e  Z d Z d    Z d   Z d   Z d   Z RS(   c         C  s    t  t |   j   | |  _ d  S(   N(   R   R   Rg   R   (   Rf   R   (    (    s   renpy/atl.pyRg   V  s    c         C  s   t  d   d  S(   Ns   Compile not implemented.(   RV   (   Rf   t   ctx(    (    s   renpy/atl.pyRb   \  s    c         C  s   d  S(   N(    (   Rf   R   (    (    s   renpy/atl.pyR   `  s    c         C  s   d |  _  d S(   s}   
        Sets self.constant to true if all expressions used in this statement
        and its children are constant.
        i    N(   R`   (   Rf   (    (    s   renpy/atl.pyt   mark_constantc  s    N(   Rr   Rs   R   R`   Rg   Rb   R   R   (    (    (    s   renpy/atl.pyR   R  s
   			t	   Statementc           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s    t  t |   j   | |  _ d  S(   N(   R   R   Rg   R   (   Rf   R   (    (    s   renpy/atl.pyRg   p  s    c         C  s   t  d   d  S(   Ns   Not implemented.(   RV   (   Rf   R   R   t   stateRA   (    (    s   renpy/atl.pyR     s    c         C  s   g  S(   N(    (   Rf   (    (    s   renpy/atl.pyR     s    c         C  s   t  S(   N(   Rn   (   Rf   R   (    (    s   renpy/atl.pyR     s    (   Rr   Rs   Rg   R   R   R   (    (    (    s   renpy/atl.pyR   n  s   			t   RawBlockc           B  s2   e  Z e Z d    Z d   Z d   Z d   Z RS(   c         C  s,   t  t |   j |  | |  _ | |  _ d  S(   N(   R   R   Rg   R   R   (   Rf   R   R   R   (    (    s   renpy/atl.pyRg     s    	c         C  sB   t  |  j  g  |  j D] } | j |  ^ q } t |  j |  S(   N(   R   R   R   Rb   t   Block(   Rf   R   RM   R   (    (    s   renpy/atl.pyRb     s    %c         C  s%   x |  j  D] } | j |  q
 Wd  S(   N(   R   R   (   Rf   R   RM   (    (    s   renpy/atl.pyR     s    c         C  sC   t  } x- |  j D]" } | j   t | | j  } q W| |  _ d  S(   N(   Ra   R   R   t   minR`   (   Rf   R`   RM   (    (    s   renpy/atl.pyR     s
    
(   Rr   Rs   Rn   R   Rg   Rb   R   R   (    (    (    s   renpy/atl.pyR     s
   				R   c           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s   t  t |   j |  | |  _ g  |  _ xI t |  D]; \ } } t | t  r5 |  j j | j	 | d f  q5 q5 W|  j j
   d  S(   Ni   (   R   R   Rg   R   t   timest	   enumerateRO   t   TimeR   t   timet   sort(   Rf   R   R   RM   t   s(    (    s   renpy/atl.pyRg     s    		$c         C  s+   x$ |  j  D] } | j |  r
 t Sq
 Wt S(   N(   R   R   R   Rn   (   Rf   R   RM   (    (    s   renpy/atl.pyR     s    c         C  s  t  |  j  | d  k	 r4 | \ } } } } }	 }
 n. d d d d |  j d  f \ } } } } }	 }
 d } d  } d  } xm| d k r|	 r |	 d \ } } t | |  } | | } n | } d } xt r| t |  j  k r d | | d  f S|  j | } | j | | | |
 |  \ } } } | d k rv| d  k rC| } n  d | | | | |	 | f t | |  } } } Pq | d k r| | | f S| d k r| d 7} | | } d  }
 q | d k r | \ } } | | } | | } | d k rt	 d   n  t
 | | |  } | d  k	 r[| | | k r[| | } | | | 7} d | | d  f Sn  | | 7} | | | } | } d } d  }
 q q W|	 r|	 d \ } } | | k r|	 j d  | } | } d  }
 qw qn  | | | f SWd  S(	   Ni    R   i   t   nextR   i   t   repeats&   ATL appears to be in an infinite loop.(   R   R   R   R   R   R   RQ   R   R   RV   t   intR   (   Rf   R   R   R   RA   t   indext   startt
   loop_startt   repeatsR   t   child_stateR   R   R   R   t   tindext   targett	   max_pauset   stmtt   countt   loop_endR   t   new_repeats(    (    s   renpy/atl.pyR     sp    .	%	/

	



	c         C  s-   g  |  j  D] } | j   D] } | ^ q q
 S(   N(   R   R   (   Rf   RM   RN   (    (    s   renpy/atl.pyR   >  s    (   Rr   Rs   Rg   R   R   R   (    (    (    s   renpy/atl.pyR     s   			dt   RawMultipurposec           B  sh   e  Z d
 Z d    Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z RS(   c         C  sY   t  t |   j |  d  |  _ d  |  _ g  |  _ g  |  _ g  |  _ d  |  _	 d |  _
 d  S(   Nt   0(   R   R   Rg   R   t   warperR   Ry   t   expressionst   splinest
   revolutiont   circles(   Rf   R   (    (    s   renpy/atl.pyRg   R  s    						c         C  s   | |  _  | |  _ | |  _ d  S(   N(   R   R   t   warp_function(   Rf   R   R   R   (    (    s   renpy/atl.pyt
   add_warper^  s    		c         C  s   |  j  j | | f  d  S(   N(   Ry   R   (   Rf   R   t   exprs(    (    s   renpy/atl.pyt   add_propertyc  s    c         C  s   |  j  j | | f  d  S(   N(   R   R   (   Rf   Rm   t   with_clause(    (    s   renpy/atl.pyt   add_expressionf  s    c         C  s   | |  _  d  S(   N(   R   (   Rf   R   (    (    s   renpy/atl.pyt   add_revolutioni  s    c         C  s   | |  _  d  S(   N(   R   (   Rf   R   (    (    s   renpy/atl.pyt   add_circlesl  s    c         C  s   |  j  j | | f  d  S(   N(   R   R   (   Rf   R   R   (    (    s   renpy/atl.pyt
   add_splineo  s    c         C  s,  t  |  j  |  j d  k r|  j d  k r|  j r|  j rt |  j  d k r|  j d \ } } | j	 |  } | r | j	 |  } n d  } t
 | t t f  r t |  j d | g  d  d g   St j j |  } t
 | t  r | j   | j   St |  j | |  Sn  t  |  j  |  j r>| j	 |  j  } n. |  j pJd } | t k rlt d |   n  g  } xX |  j D]M \ } } | t k rt d t   n  | j	 |  }	 | j | |	 f  q|Wg  }
 xk |  j D]` \ } } | t k rt d t   n  g  | D] } | j	 |  ^ q} |
 j | | f  qWx |  j D] \ } } y | j	 |  }	 Wn t d |   n Xt
 |	 t  st d |   n  |	 j   |	 j d  k rt d	 |   n  | j |	 j  qKW| j	 |  j  } | j	 |  j  } t |  j | | | |  j | |
  S(
   Ni   i    R   R   s$   ATL Warper %s is unknown at runtime.s&   ATL Property %s is unknown at runtime.s4   Could not evaluate expression %r when compiling ATL.sY   Expression %r is not an ATL transform, and so cannot be included in an ATL interpolation.sD   ATL transform %r is too complicated to be included in interpolation.(   R   R   R   R   R   Ry   R   RQ   R   Rj   RO   R   R   R   R   t   easyt   displayableRt   Rb   R   t   ChildR
   RV   t
   PROPERTIESt   propertyR   R   R   R   R   (   Rf   R   Rm   t   withexprR   t
   transitionR   Ry   R   R   R   R   RM   t   valuest   _withR   R   (    (    s   renpy/atl.pyRb   r  sd    



	"
c         C  s  t  } t | t |  j   } t | t |  j   } t | t |  j   } x, |  j D]! \ } } t | t |   } qX Wx= |  j D]2 \ } } x# | D] } t | t |   } q Wq WxA |  j D]6 \ } } t | t |   } t | t |   } q W| |  _	 d  S(   N(
   Ra   R   t   is_constant_exprR   R   R   Ry   R   R   R`   (   Rf   R`   t   _nameRm   R   R   (    (    s   renpy/atl.pyR     s    c         C  s   x{ |  j  D]p \ } } y | j |  } Wn
 q
 n Xt | t  rY | j j |  d  Sy t j j |  Wq
 q
 q
 Xq
 Wd  S(   N(   R   Rj   RO   Rt   R_   R   R   R   (   Rf   R   RM   t   _j(    (    s   renpy/atl.pyR     s    N(   Rr   Rs   R   R   Rg   R   R   R   R   R   R   Rb   R   R   (    (    (    s   renpy/atl.pyR   N  s   								T	t   RawContainsExprc           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R   Rg   t
   expression(   Rf   R   Rm   (    (    s   renpy/atl.pyRg     s    c         C  s2   t  |  j  | j |  j  } t |  j | d   S(   N(   R   R   Rj   R   R   R   (   Rf   R   R   (    (    s   renpy/atl.pyRb     s    c         C  s   t  |  j  |  _ d  S(   N(   R   R   R`   (   Rf   (    (    s   renpy/atl.pyR     s    (   Rr   Rs   Rg   Rb   R   (    (    (    s   renpy/atl.pyR     s   		t   RawChildc           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s&   t  t |   j |  | g |  _ d  S(   N(   R   R   Rg   R   (   Rf   R   R   (    (    s   renpy/atl.pyRg     s    c         C  s   g  } x6 |  j  D]+ } | j t j j j | d | j  q Wt j j j d d  } x | D] } | j	 |  q^ Wt
 |  j | d   S(   NRe   t   layoutt   fixed(   R   R   R   R   R   R   Re   R   t   MultiBoxt   addR   R   R   (   Rf   R   R   RM   t   box(    (    s   renpy/atl.pyRb   	  s    )c         C  sC   t  } x- |  j D]" } | j   t | | j  } q W| |  _ d  S(   N(   Ra   R   R   R   R`   (   Rf   R`   RM   (    (    s   renpy/atl.pyR     s
    
(   Rr   Rs   Rg   Rb   R   (    (    (    s   renpy/atl.pyR     s   		R   c           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s,   t  t |   j |  | |  _ | |  _ d  S(   N(   R   R   Rg   R   R   (   Rf   R   R   R   (    (    s   renpy/atl.pyRg   %  s    	c         C  s   t  |  j  | j } |  j } | j rJ |  j j | j  } | j   n  | d  k	 r | t	 j
 j j k	 r |  j d  k	 r |  j d | d |  } | j   n | } | j | d t |  j | _ d | d  f S(   Nt
   old_widgett
   new_widgett	   duplicateR   (   R   R   R   R   R   R   R   t   _uniqueR   R   R   R   R   R   t	   set_childRn   (   Rf   R   R   R   RA   t	   old_childR   (    (    s   renpy/atl.pyR   ,  s    			0	c         C  s
   |  j  g S(   N(   R   (   Rf   (    (    s   renpy/atl.pyR   D  s    (   Rr   Rs   Rg   R   R   (    (    (    s   renpy/atl.pyR   #  s   		R   c           B  s   e  Z d    Z d   Z RS(   c         C  sP   t  t |   j |  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(	   R   R   Rg   R   R   Ry   R   R   R   (   Rf   R   R   R   Ry   R   R   R   (    (    s   renpy/atl.pyRg   K  s    					c         C  s  t  |  j  t j |  j |  j  } |  j d k rg | d  k rg | j d  k	 s^ | j d k rg t } n t	 } |  j
 r t d | |  j
  } n d } | d k  r d } n | d k r d } n  | |  } | d  k rt j j j   } | j | j  t	 }	 xE |  j D]: \ }
 } t | |
 |  |
 d k r	| | _ t }	 q	q	W| j j |  } d  } g  } |  j } |  j } | s|	 rt j j r| j d  k	 rx6 d d d d	 d
 d d d g D] } | j | d   qW| d  k	 r| j | j _ | j | j _ | j | j _ | j | j _ | j j } | j } | j j  } | j  } | d k r| | k  rn| d 8} n  | | d 8} n6 | d k r| | k r| d 7} n  | | d 7} n  | | | | f } q| j j p| j j } | | j | j j  | j  f } n  x= |  j! D]2 \ } } | j" | t# | j |  g | f  qW| | | f } xK |  j D]. \ }
 } |
 | k r\t | j |
 |  q\q\Wn | \ } } } xL | j$   D]> \ }
 \ } } t% | | | t& |
  } t | j |
 |  qW| d  k	 rX| \ } } } } t% | | | t'  } | | j _ | | j _ t% | | | t'  | j _  n  x6 | D]. \ } } t( | |  } t | j | |  q_W| st j j) r| |  j
 k rd | |  j
 d  f S|  j r|  j r|  j! rd | t* d |  j
 |  f Sd | d f Sd  S(   NR   i    g      ?g        R1   R   R   R   R   R   R    R!   R"   t	   clockwiseih  t   counterclockwiseR   R   (+   R   R   R
   t   getR   R   Rz   R   R   Rn   R   R   R   R   R   t   TransformStateR   R   Ry   t   setattrt
   last_anglet   diffR   R   R   t   automatic_polar_motionR   R   R    R!   R"   R1   R2   R   R   t   getattrR   RK   R   R   RU   t   atl_one_framet   max(   Rf   R   R   R   RA   R   t   firstt   completet   newtst	   has_angleR   RG   t   linearR   R   t   revdirR   RM   t
   startanglet   endanglet   startradiust	   endradiusR  R   R   t   oldt   newR   R1   (    (    s   renpy/atl.pyR   Z  s    							'			!*#(   Rr   Rs   Rg   R   (    (    (    s   renpy/atl.pyR   I  s   	t	   RawRepeatc           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R!  Rg   R   (   Rf   R   R   (    (    s   renpy/atl.pyRg     s    c         C  sD   t  |  j  |  j } | d  k	 r4 | j |  } n  t |  j |  S(   N(   R   R   R   R   Rj   t   Repeat(   Rf   R   R   (    (    s   renpy/atl.pyRb     s
    	c         C  s   t  |  j  |  _ d  S(   N(   R   R   R`   (   Rf   (    (    s   renpy/atl.pyR     s    (   Rr   Rs   Rg   Rb   R   (    (    (    s   renpy/atl.pyR!    s   		R"  c           B  s   e  Z d    Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R"  Rg   R   (   Rf   R   R   (    (    s   renpy/atl.pyRg     s    c         C  s   d |  j  | f d f S(   NR   i    (   R   (   Rf   R   R   R   RA   (    (    s   renpy/atl.pyR   
  s    (   Rr   Rs   Rg   R   (    (    (    s   renpy/atl.pyR"    s   	t   RawParallelc           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s&   t  t |   j |  | g |  _ d  S(   N(   R   R#  Rg   t   blocks(   Rf   R   Rw   (    (    s   renpy/atl.pyRg     s    c         C  s/   t  |  j g  |  j D] } | j |  ^ q  S(   N(   t   ParallelR   R$  Rb   (   Rf   R   RM   (    (    s   renpy/atl.pyRb     s    c         C  s%   x |  j  D] } | j |  q
 Wd  S(   N(   R$  R   (   Rf   R   RM   (    (    s   renpy/atl.pyR     s    c         C  sC   t  } x- |  j D]" } | j   t | | j  } q W| |  _ d  S(   N(   Ra   R$  R   R   R`   (   Rf   R`   RM   (    (    s   renpy/atl.pyR     s
    
(   Rr   Rs   Rg   Rb   R   R   (    (    (    s   renpy/atl.pyR#    s   			R%  c           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R%  Rg   R$  (   Rf   R   R$  (    (    s   renpy/atl.pyRg   *  s    c         C  s+   x$ |  j  D] } | j |  r
 t Sq
 Wt S(   N(   R$  R   R   Rn   (   Rf   R   RM   (    (    s   renpy/atl.pyR   .  s    c         C  s+  t  |  j  | d  k r> g  |  j D] } | d  f ^ q# } n  g  } g  } g  } x | D] \ } }	 | j | | |	 |  \ }
 } } | d  k	 r | j |  n  |
 d k r | j | | f  qW |
 d k r | j |  qW |
 d k rW |
 | | f SqW W| rd | t |  f Sd t |  d  f Sd  S(   NR   R   R   (   R   R   R   R$  R   R   R   (   Rf   R   R   R   RA   RM   t   leftt   pausest   newstatet   istateR   R   R   (    (    s   renpy/atl.pyR   6  s&    %!c         C  s-   g  |  j  D] } | j   D] } | ^ q q
 S(   N(   R$  R   (   Rf   RM   RN   (    (    s   renpy/atl.pyR   Y  s    (   Rr   Rs   Rg   R   R   R   (    (    (    s   renpy/atl.pyR%  (  s   			#t	   RawChoicec           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s,   t  t |   j |  | | f g |  _ d  S(   N(   R   R*  Rg   t   choices(   Rf   R   t   chanceRw   (    (    s   renpy/atl.pyRg   a  s    c         C  sQ   t  |  j  t |  j g  |  j D]* \ } } | j |  | j |  f ^ q   S(   N(   R   R   t   ChoiceR+  Rj   Rb   (   Rf   R   R,  Rw   (    (    s   renpy/atl.pyRb   f  s    c         C  s+   x$ |  j  D] \ } } | j |  q
 Wd  S(   N(   R+  R   (   Rf   R   t   _iRN   (    (    s   renpy/atl.pyR   j  s    c         C  sI   t  } x3 |  j D]( \ } } | j   t | | j  } q W| |  _ d  S(   N(   Ra   R+  R   R   R`   (   Rf   R`   t   _chanceRw   (    (    s   renpy/atl.pyR   n  s
    
(   Rr   Rs   Rg   Rb   R   R   (    (    (    s   renpy/atl.pyR*  _  s   			R-  c           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R-  Rg   R+  (   Rf   R   R+  (    (    s   renpy/atl.pyRg   z  s    c         C  s/   x( |  j  D] } | d j |  r
 t Sq
 Wt S(   Ni   (   R+  R   R   Rn   (   Rf   R   RM   (    (    s   renpy/atl.pyR     s    c         C  s   t  |  j  | d  k r d } x! |  j D] \ } } | | 7} q) Wt j d |  } x1 |  j D]& \ } } | | k  r{ Pn  | | 8} q_ Wd  }	 n | \ } }	 | j | | |	 |  \ }
 } } |
 d k r d | | f | f S|
 | d  f Sd  S(   Ni    R   (   R   R   R   R+  t   randomt   uniformR   (   Rf   R   R   R   RA   t   totalR,  t   choicet   nt   cstateR   R   R   (    (    s   renpy/atl.pyR     s     	!c         C  s1   g  |  j  D]# } | d j   D] } | ^ q q
 S(   Ni   (   R+  R   (   Rf   RM   RN   (    (    s   renpy/atl.pyR     s    (   Rr   Rs   Rg   R   R   R   (    (    (    s   renpy/atl.pyR-  x  s   			t   RawTimec           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R6  Rg   R   (   Rf   R   R   (    (    s   renpy/atl.pyRg     s    c         C  s)   t  |  j  t |  j | j |  j   S(   N(   R   R   R   Rj   R   (   Rf   R   (    (    s   renpy/atl.pyRb     s    c         C  s   t  |  j  |  _ d  S(   N(   R   R   R`   (   Rf   (    (    s   renpy/atl.pyR     s    (   Rr   Rs   Rg   Rb   R   (    (    (    s   renpy/atl.pyR6    s   		R   c           B  s   e  Z d    Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R   Rg   R   (   Rf   R   R   (    (    s   renpy/atl.pyRg     s    c         C  s   d S(   NR   (   s   continueNN(   R   (   Rf   R   R   R   RA   (    (    s   renpy/atl.pyR     s    (   Rr   Rs   Rg   R   (    (    (    s   renpy/atl.pyR     s   	t   RawOnc           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  sA   t  t |   j |  i  |  _ x | D] } | |  j | <q& Wd  S(   N(   R   R7  Rg   t   handlers(   Rf   R   t   namesRw   RM   (    (    s   renpy/atl.pyRg     s    	c         C  sV   t  |  j  i  } x0 |  j j   D] \ } } | j |  | | <q# Wt |  j |  S(   N(   R   R   R8  R   Rb   t   On(   Rf   R   R8  R   RG   (    (    s   renpy/atl.pyRb     s
    c         C  s+   x$ |  j  j   D] } | j |  q Wd  S(   N(   R8  t
   itervaluesR   (   Rf   R   RM   (    (    s   renpy/atl.pyR     s    c         C  sI   t  } x3 |  j j   D]" } | j   t | | j  } q W| |  _ d  S(   N(   Ra   R8  R;  R   R   R`   (   Rf   R`   Rw   (    (    s   renpy/atl.pyR     s
    
(   Rr   Rs   Rg   Rb   R   R   (    (    (    s   renpy/atl.pyR7    s   		
	R:  c           B  s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R:  Rg   R8  (   Rf   R   R8  (    (    s   renpy/atl.pyRg     s    c         C  s   | |  j  k r t St Sd  S(   N(   R8  R   Rn   (   Rf   R   (    (    s   renpy/atl.pyR     s    c         C  s
  t  |  j  | d  k r0 d | d  } } } n | \ } } } xe | D]] } | |  j k rF | d k rp | j p | d k o | j }	 |	 s | } | } d  } q qF qF Wx\t r| |  j k r d | | | f d  f S|  j | j | | | | |  \ }
 } } |
 d k rP| d k s%| d k r:t | _	 t | _
 n  d | | | f | f S|
 d k r| d k s| d k s| d k rd  } n d } | | } d  } q q |
 d k r | \ } } | |  j k rt | | | d  } d  } q n  d | | f d  f Sq Wd  S(	   NR   R   R   R   R   t   defaultR   i   (   R   R   R   R8  R   R   R   R   Rn   t   hide_responset   replaced_responseR  (   Rf   R   R   R   RA   R   R   R5  R   t
   lock_eventR   R   R   (    (    s   renpy/atl.pyR     sD    *	,	$	
c         C  s3   g  |  j  j   D] } | j   D] } | ^ q  q S(   N(   R8  R;  R   (   Rf   RM   RN   (    (    s   renpy/atl.pyR   ;  s    (   Rr   Rs   Rg   R   R   R   (    (    (    s   renpy/atl.pyR:    s   			Et   RawEventc           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   R@  Rg   R   (   Rf   R   R   (    (    s   renpy/atl.pyRg   C  s    c         C  s   t  |  j |  j  S(   N(   t   EventR   R   (   Rf   R   (    (    s   renpy/atl.pyRb   H  s    c         C  s   t  |  _ d  S(   N(   Ra   R`   (   Rf   (    (    s   renpy/atl.pyR   K  s    (   Rr   Rs   Rg   Rb   R   (    (    (    s   renpy/atl.pyR@  A  s   		RA  c           B  s   e  Z d    Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   RA  Rg   R   (   Rf   R   R   (    (    s   renpy/atl.pyRg   Q  s    c         C  s   d |  j  | f d  f S(   NR   (   R   R   (   Rf   R   R   R   RA   (    (    s   renpy/atl.pyR   V  s    (   Rr   Rs   Rg   R   (    (    (    s   renpy/atl.pyRA  O  s   	t   RawFunctionc           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   RB  Rg   Rm   (   Rf   R   Rm   (    (    s   renpy/atl.pyRg   \  s    c         C  s)   t  |  j  t |  j | j |  j   S(   N(   R   R   t   FunctionRj   Rm   (   Rf   R   (    (    s   renpy/atl.pyRb   a  s    c         C  s   t  |  j  |  _ d  S(   N(   R   Rm   R`   (   Rf   (    (    s   renpy/atl.pyR   e  s    (   Rr   Rs   Rg   Rb   R   (    (    (    s   renpy/atl.pyRB  Z  s   		RC  c           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s#   t  t |   j |  | |  _ d  S(   N(   R   RC  Rg   t   function(   Rf   R   RD  (    (    s   renpy/atl.pyRg   k  s    c         C  s   t  S(   N(   R   (   Rf   R   (    (    s   renpy/atl.pyR   p  s    c         C  s9   |  j  | | | j  } | d  k	 r1 d d  | f Sd Sd  S(   NR   R   i    (   s   nexti    N(   RD  R   R   (   Rf   R   R   R   RA   t   fr(    (    s   renpy/atl.pyR   s  s    (   Rr   Rs   Rg   R   R   (    (    (    s   renpy/atl.pyRC  i  s   		c         C  s  |  j    |  j   } g  } t } x|  j s|  j   } |  j d  rn |  j   } | j t | |   nE|  j d  r |  j d  |  j	   |  j
 d  t |  j    } | j |  n|  j d  rY|  j   } | r
|  j d  | j t | |   q|  j d  |  j	   |  j
 d  t |  j    } | j t | |   nZ|  j d  r|  j d  |  j	   |  j
 d  t |  j    } | j t | |   n|  j d  r3|  j   } | sd } n  |  j d  |  j	   |  j
 d  t |  j    } | j t | | |   n|  j d	  r|  j |  j  g }	 x< |  j d
  r|  j   }
 |
 d  k rPn  |	 j |
  qZW|  j d  |  j	   |  j
 d	  t |  j    } | j t | |	 |   n|  j d  r/|  j |  j  } |  j d  | j t | |   n|  j d  rv|  j |  j  } |  j d  | j t | |   n=|  j d  r|  j |  j  }
 |  j d  | j t | |
   n|  j d  r|  j d  | j d   n|  j d  r|  j d  t } nt j j |  } t } t } |  j   } |  j   } | t k rk|  j |  j  } d  } nX | d k rd  } |  j |  j  } |  j |  j  } n |  j  |  d  } d  } d } | j! | | |  xt r| } t } |  j d  r qn  |  j d  r"| j" d  qn  |  j d  rD| j" d  qn  |  j d  ru|  j |  j  } | j# |  n  |  j   } |  j   } | t$ k r|  j |  j  } g  } x, |  j d  r| j |  j |  j   qW| r| j |  | j% | |  q| j& | |  qn  |  j  |  |  j   } | s?Pn  | rU|  j' d  n  t } |  j d  r|  j |  j  } n d  } | j( | |  qW|  j d  | j |  |  j)   r|  j    q% n  |  j d
 d  q% Wg  } d  } x| D]} t* | t  r3t* | t  r3| j+ j, | j+  qn t* | t  rjt* | t  rj| j- j, | j-  qn t* | t  rt* | t  r| j. j, | j.  qnO t* | t  rt* | t  r| j/ j0 | j/  qn | d  k r| } qn  | j |  | } qWt1 | | |  S(   NR   Rw   t   :t   containss   contains expressiont   parallelR3  s   1.0t   ont   ,R   RD  R   t   passR   t   warpR   R
  R  R   t   knotsw   ATL statement contains two expressions in a row; is one of them a misspelled property? If not, separate them with pass.t   witht   ATLs   comma or end of line(2   t   advancet   get_locationRn   t   eobt   keywordt   simple_expressionR   R!  t   requiret
   expect_eolt   expect_blockt	   parse_atlt   subblock_lexert   expect_noblockR   R   R#  R*  t   wordt   matchR   R7  R6  RB  R@  R   R   R_   R   t
   checkpointR   R
   t   revertR   R   R   R   R   R   t   errorR   t   eolRO   R$  R   R+  R   R8  t   updateR   (   t   lt	   block_locR   R   R   R   Rw   Rm   R,  R9  R   R   t   rmt   last_expressiont   this_expressiont   cpR   R   R   t   propt   knotst	   with_exprt   mergedR  R   (    (    s   renpy/atl.pyRX  }  s.   



	

				

(:   t
   __future__R    t   renpy.displayR   t   renpy.pyanalysisR0  R   R   R
   R   R   R   t   objectt   SentinelR   R   R   R   R   R   R   R   RJ   RK   RU   R^   Rc   Rd   t   ObjectRt   t
   pyanalysist   AnalysisR   Ra   R   R   R   R   R   R   R   R   R   R!  R"  R#  R%  R*  R-  R6  R   R7  R:  R@  RA  RB  RC  RX  (    (    (    s   renpy/atl.pyt   <module>   s   							
			$	 G-%"&73"X