
:a(Hc        S   @   s  d  d k  Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k	 Z	 d  d k
 Z
 d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z l Z l Z e i   Z d Z d Z d Z d Z d Z d Z d Z e i   Z  d Z  d a! d Z" d Z# e$ Z% d Z& d	   Z' e'   d
 a( d a) d a* d a+ d   Z, h  Z- d   Z. h  a/ h  a0 h  a1 d   Z2 h  a3 d   Z4 d   Z5 d a6 h  a7 d   Z8 d d  Z9 g  a: t: i; d g d  t: i; d g d  d d  Z< d   Z= d d d d d d d  Z? d e$ d  Z@ d ZA d^   ZB d_ d` da  ZC db   ZD e$ dc  ZE dd   ZF de   ZG df   ZH dg   ZI dh   ZJ e di  ZK dj   ZL dk   ZM e$ dl  ZN e$ dm  ZO dn ZP do   ZQ h  dp dq <d  dr <d ds <dt du <dv dw <dx dy <dz d{ <d| d} <d~ d <d dn <ZR d   ZS dt aT e
 iU d  aV h  aW d   ZX d   ZY d   ZZ d   Z[ d   Z\ d   Z] d d  Z^ h  a_ d   Z` d   Za e\   ea   h  ab d d d d g tb d <d d d d g tb d <d d d d g tb d <d d d d g tb d <h  ac d   Zd d   Ze h  af d   Zg d   Zh d   Zi d   Zj d   Zk d   Zl d   Zm d   Zn d S(   iN(   t   alwayst   voidt   exiti   i<   i   iX  i    t   en_USc          C   s_   xX t  d t i   d d g D]: }  y t i t i |   PWq t i j
 o
 q q Xq Wd  S(   Nt    i    R   (   t   languaget   localet   getdefaultlocalet	   setlocalet   LC_ALLt   Error(   t   attempt(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   set_localeO   s     s   Default Saves   DejaVuSans.ttfs   acknowtt.ttfs   ../data/c           C   s   t  i   d  S(   N(   t   sysR   (    (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt	   quit_gamec   s    c           C   sr   d t  d <d t  d <d t  d <d t  d <d t  d <d t  d	 <d t  d
 <d t  d <d t  d <d t  d <d t  d <d  S(   Ni   t   whitei    t   blackt   redt   greent   bluei}   t   dark_redt
   dark_greent	   dark_bluei2   t	   light_redt   light_greent
   light_blue(   i   i   i   i   (   i    i    i    i   (   i   i    i    i   (   i    i   i    i   (   i    i    i   i   (   i}   i    i    i   (   i    i}   i    i   (   i    i    i}   i   (   i   i2   i2   i   (   i2   i   i2   i   (   i2   i2   i   i   (   t   colors(    (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   fill_colorsi   s    









c          C   s   t  i i t d  }  t  i |   } x | D] } t |  d j oh | d d j p | d d j oF t i i t  i i |  |   i	   t
 | <t
 | i d	 t i  q+ q+ Wd S(
   sF   
load_images() loads all of the images in the data/images/ directory.
t   imagesi   is   .pngs   .jpgi   i    N(   i   i    i   i   (   t   ost   patht   joint   data_loct   listdirt   lent   pygamet   imaget   loadt   convertR   t   set_colorkeyt   RLEACCEL(   t	   image_dirt
   image_listt   image_filename(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   load_imagesz   s     $	"c          C   s  t  o d Sn t i i   p t i i d  d a  d Sn t i i	 t
 d  }  t t i i	 d d   } x,| D]$} t | d d  t | d  t j o | d g } n | d } x | D] } t i i	 |  |  } t i i |  p% t i i d |  t i d  q t i i |  } t i | d	  p g  t | d	 <n t | d	 i h  | d <| d
 < t o t i i d |  q q Wqt Wd S(   sd   
load_sounds() loads all of the sounds in the data/sounds/ directory,
defined in sounds/sounds.dat.
NsD   WARNING: Could not start the mixer, even though sound is requested!
i   t   soundss
   sounds.datt   filenamet   Sounds-   ERROR: Cannot load nonexistent soundfile %s!
t   idt   sounds   D: Loaded soundfile %s
(   s   filename(   t   nosoundR#   t   mixert   get_initR   t   stderrt   writeR   R   R   R    t   generic_loadt   check_required_fieldst   typet   listt   isfileR   R/   R-   t   has_keyt   appendt   debug(   t	   sound_dirt   sound_class_listt   sound_classt	   filenamesR.   t   real_filenameR1   (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   load_sounds   s:    	 
 	c         C   s   t  o d Sn |  t j o t i i d |   d Sn t i t |   } t o t i i d | d  n | d i   d S(   s5   
play_sound() plays a sound from a particular class.
Ns5   WARNING: Requesting a sound of unavailable class %s!
s   D: Playing sound %s.
R.   R1   (	   R2   R-   R   R5   R6   t   randomt   choiceR>   t   play(   RA   t   random_sound(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   play_sound   s    c       
   C   s  t  o d Sn h  a t i i t d d  t i i t t  d  f }  xD|  D]<} t i i |  ox t i	 |  D] \ } } } t i i
 |  \ } } | i   d j o t i |  p g  t | <n x | D] } t |  d j op | d d j p | d d j oN t | i t i i | | |   t o  t i i d	 t | d
  q`q q Wqx qx WqO y t i |  WqO qO XqO Wd S(   s   
load_music() loads music for the game.  It looks in multiple locations:

* music/ in the install directory for E:S; and
* music/ in the save folder.
Ns   ..t   musics   .svni   it   oggt   mp3s   D: Loaded musicfile %s
i(   R2   t
   music_dictR   R   R   R    t   get_save_foldert   Truet   isdirt   walkt   splitt   lowerR<   R"   R=   R>   R   R5   R6   t   makedirs(   t   music_pathst
   music_patht   roott   dirst   filest   headt   tailt	   file_name(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   load_music   s4       "#(RJ   c         C   sb  t  p t t  d j o d  Sn t i |   p d  Sn t t |   d j o d  Sn t i i i   o |  d j o d  Sn |  d j oD t i i i   t i i i	 t
 i t |    t i i i   n t d j o+ t i i   t t
 i
   d  d a nU t t i i   j o d  Sn d a t i i i	 t
 i t |    t i i i   d  S(   Ni    RJ   i'  i  (   R2   R"   RM   R<   R#   R3   RJ   t   get_busyt   stopR%   RE   RF   RG   t
   delay_timet   timet	   get_tickst   int(   t   musicdir(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   play_music	  s&          +  i3   c   	      C   s  | d j oq | i  |  } | d j o$ | d | d d | d f } q~ | d j o  | d | d | d f } q~ n | d j p | t |  j o) | i | d |  } |  i | |  n | i | |  d |  } |  i | |  | i  | |   } | d | d | d f } | i d  | i | | d |  } |  i | |  | i d  | i  | |  } | d | d | d f } | i | | d d |  } |  i | |  d  S(   Ni    i   i   i(   t   sizeR"   t   rendert   blitt   set_underline(	   t   surfacet   string_to_printt   fontt   underline_chart   xyt   colort   alignRf   t   text(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   print_string-  s*     $ $ c         C   s  | } | i  d d  i d  } x | D] } | d 7} | i |  }	 | d j o# | d | d |	 d f } q( n | i | d |  }
 | d | d |	 d | j o  | d | d |	 d f } n |  i |
 |  | d |	 d | d f } q( Wd  S(   Ns   
s    \n t    s   \n i    i   (   t   replaceRR   Rf   Rg   Rh   (   Rj   Rk   Rl   t   widthRn   Ro   t   start_xyt   string_arrayt   stringRf   Rq   (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   print_multilineE  s     
! i   c      	   C   s  | d  j o t d d } n | d  j o t d d d d f } n | d  j o t d } n | d  j o t d } n | d  j o t d } n t i | | d | d | d | d f  t i | | d d | d d | d d | d d f  t t |  | | d d	 | d d
 | d d
 f |  h  } t t  | t	 i
 | d | d d d | d | d d
 f d d d t d d  <t	 i |  d  S(   Ni    i   i   id   i2   R   R   i   i
   i   t   OKt   Oi   (   id   i2   (   t   NoneRl   t   screen_sizeR   t   screent   fillRy   R    RO   t   buttonst   make_norm_buttont   show_buttons(   Rk   t   box_fontRn   Rf   t   bg_colort	   out_colort
   text_colort   menu_buttons(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   create_dialogX  s"    ,< Wt   YESt   NOc	      	   C   sQ  t  i | | d | d | d | d f  t  i | | d d | d d | d d | d d f  t t  |  | | d d | d d | d d f |  h  }	 | d j o t t  |	 t i | d | d d d | d | d d f d | d d t d d  <t t  |	 t i | d | d d d | d | d d f d | d d t d d  <n t t  |	 t i | d | d | d d f d | d | d d t d d  <t t  |	 t i | d | d d	 | d | d d f d | d | d d t d d  <t }
 | o
 t }
 n t i	 |	 d t i
 |
  S(   Ni    i   i   i
   i   R   R   in   id   i2   t   Yi   t   Nit   key_callback(   R   R   (   id   i2   (   id   i2   (   R~   R   Ry   R    RO   R   R   Rl   t   FalseR   t   simple_key_handler(   Rk   R   Rn   Rf   R   R   R   t   button_namest   reverse_key_contextR   t   default(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   create_yesnor  s    ,< [_S_
t   at   bt   ct   dt   et   ft   gt   ht   it   jt   kt   lt   mt   nt   ot   pt   qt   rt   st   tt   ut   vt   wt   xt   yt   zt   At   Bt   Ct   Dt   Et   Ft   Gt   Ht   It   Jt   Kt   Lt   MR   R{   t   Pt   Qt   Rt   St   Tt   Ut   Vt   Wt   XR   t   Zt   0t   1t   2t   3t   4t   5t   6t   7t   8t   9t   .Rs   c
            s  t  i |  d  d  d  d f  t  i |  d d  d d  d d  d d f  t  i |  d d  d  d d  d d d f  t t  |    d d  d d  d d f   t |  a d   }
 h  } |
 | t i  d  d d d	  d  d d f d d d t d d  <| a d } h  t	 t
 i <t	 t
 i <t	 t
 i <t	 t
 i <  h  d t
 i <d t
 i <d t
 i <d t
 i < h  d t
 i <d t
 i <d t
 i <d t
 i <     f d   }      f d   }     f d   }   f d   }    f d   } t i | d | d | d | d | d | S(   Ni    i   i   i   i   i
   i   c           S   s   t  S(   N(   t   work_string(    (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt	   give_text  s    i2   id   Rz   R   ii   c   	         s  t  } t i t i t i t i f } | \ } } } } x| D]}}   | olt  }   | c d 7<  |  | j od   | < | d j o  | c d 8<n t } | | j o1 t d j o$ t t d  t t a t d 8a q| | j o- t t	 t  j  o t t  t t d a q| | j o t d j o t d 8a q| | j o! t t	 t  j  o t d 7a qt  } n  | p d   | <d  | <n | p | } q= q= W| S(   Ni   i    i   (
   R   R#   t   K_BACKSPACEt   K_DELETEt   K_LEFTt   K_RIGHTRO   t
   cursor_locR   R"   (	   t   tick_lent   need_redrawt   keyst	   backspacet   deletet   leftt   rightt   keyt   i_need_redraw(   t   key_down_time_dictt   key_down_dictt   repeat_timing_dict(    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   on_tick  s>     
  

c       
      s     i  t t   }  t i   d d  d  d d  d d d f  t i   d d |  d  d  d d d |  d f  t t t   d  d d	  d  d d f   d  S(
   Ni    i   i   i   i   i   i   ii   (   Rf   R   R   R~   R   Rr   (   t   draw_cursor_pos(   R   R   Rn   t   text_bg_colorRf   (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   do_refresh  s    '/c            s   |  i  } | t i t i f j o t Sn | t i j o d Sn |  i t j o< t  j  o' t t  |  i t t a t d 7a n d  Sn t	   | <d  | <d  S(   NR   i   i   (
   R   R#   t   K_RETURNt
   K_KP_ENTERR   t   K_ESCAPEt   unicodet   valid_input_charactersR   RO   (   t   eventR   (   R   R   t
   max_length(    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   on_key_down  s    	
c            s   |  i  } t   | <d  S(   N(   R   R   (   R   R   (   R   (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt	   on_key_up  s    	c            sH  |  i  d j o4|  i d  d d j o|  i d  d  d d j o |  i d  d  d d j  o |  i d  d  d d j  o |  i d  d d } d } x t d t t   D]_ }   i t |   d } | | d | j o | d a Pn | | j o | a Pn | } q Wt t  a qDn d  S(   Ni   i    i   i   i   (   t   buttont   post   rangeR"   R   Rf   R   (   R   t   cursor_xt   prev_xR   t   curr_x(   R   Rn   Rf   (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   on_click  s     @H 

t   click_callbackt   tick_callbackR   t   keyup_callbackt   refresh_callback(   id   i2   (   R~   R   Ry   R"   R   R   R   Rl   R   R   R#   R   R   R   R   R   (   t   descript_textt   starting_textR   Rn   Rf   R   R   R   R   R   R   R   t
   sel_buttonR   R   R   R   R   (    (	   R   R   Rn   Rf   R   R   R   R   R   s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   create_textbox  sH    ,<<+	Q)	R   R   c         C   st   t  i t | |  d |  d | d | d f  t  i t | |  d d |  d d | d d | d d f  d  S(   Ni    i   i   (   R~   R   R   (   Rn   Rf   t   outline_colort   inner_color(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   create_norm_box   s    0c         C   s  t  i d |  d t } t  i d d  } t |  d j o | d i   o | d t  i d  j o< | d t  i d  j o" | i | d  i | d  Sn | d t  i d  j o< | d t  i d  j o" | i | d  i | d  Sq n | S(	   Ns   %0.2ft   groupings   %01.1fg?i   i   i    i   (   R   t   formatRO   R"   t   isdigitt   strt   rstript   lstrip(   t   numbert   raw_with_commast   locale_test(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   add_commas&  s    %4"4&c         C   sH   |  d d j p | o t  i d |  d  Sn t  i d |  d  Sd  S(   Nid   i    s   %.2f%%g      Y@s   %d%%(   R   R  (   t   raw_percentt	   show_full(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   to_percent3  s    c         C   s3   |  d } | d j o |  | Sn |  d | Sd  S(   Nid   i2   (    (   t   valuet   sub_percent(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   nearest_percent;  s    
c         C   sW   |  d j  o t  d Sn; |  d j  o t  d Sn" |  d j  o t  d Sn	 t  d Sd  S(   Ni	  t   detect_str_lowi  t   detect_str_moderateiL  t   detect_str_hight   detect_str_critical(   t   strings(   R  (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   percent_to_detect_strE  s    c         C   s   |  t  t  } t |  S(   N(   t   floatt   seconds_per_dayR  (   t   amountt   display_cpu(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   to_cpuT  s    c         C   s   d } t  |   } | d j  o t |   } n | d j  o d } d } nG | d j  o d } d } n* | d j  o d } d } n d } d	 } d
 t |   | } | | 7} | S(   NR   i@B i ʚ;t   mil    J)t   bil     I5 t   trt   qus   %3.3f(   t   absR  R  (   R  t	   to_returnt
   abs_amountt   divisort   unit(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   to_moneyZ  s$    



c         C   s   t  i d d  } |  | j S(   Ni   i'  (   RE   t   randint(   t   roll_againstt   rand_num(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   roll_percentt  s    c         C   s>   | t  t  } d |  } | | } d | } t i   | j  S(   Ni   (   R  R  RE   (   t   chance_per_dayt   secondst   portion_of_dayt   inv_chance_per_dayt
   inv_chancet   chance(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   roll_chance}  s
    


c         C   sh   | | } | d j  o t  |  t |  } d } n d } |  | t } |  | t } | | } | | S(   Ni    (   t   current_shareR  (   t   num_per_dayt   time_of_dayt   seconds_passedt	   last_timet   share_yesterdayt   previously_passedt   current_passedt   passed_this_tick(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyR2    s    
	


c         C   s`   |  d d j o t  |  d  d Sn6 |  d d j o t  |  d  d Sn t  |   d Sd  S(	   Ni<   i0   i   s    daysi   s    hourss    minutesi  (   R  (   t   raw_time(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   to_time  s
    c         c   sJ   xC t  i   D]5 } x, | i D]! } |  o | | f Vq | Vq Wq Wd  S(   N(   t	   locationst   valuest   bases(   t   with_loct   base_loct   base(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt	   all_bases  s     
 c         C   s   t  i i d  o( t o  t  i i t  i d d  } nM t  i i t  i i t   \ } } | i	   d j o t
 d t d  n t  i i | d  } t  i i |  p t  i |  n |  o | Sn | Sd  S(   Nt   HOMEs   .endgamet   datas	   data_loc=s    breaks get_save_foldert   saves(   R   t   environR<   t   force_single_dirR   R   RR   t   normpathR    RS   t
   ValueErrort   existsRT   (   t   just_pref_dirt   pref_dirt   data_subdirt   save_dir(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyRN     s     $t   singularity_savefile_r4c         C   s   |  a  t   } t i i | |  d  } t | d  } t i t |  t i t	 |  t i t
 |  t i t |  t i t |  t i t |  | i   d  S(   Ns   .savR   (   t   default_savegame_nameRN   R   R   R   t   opent   picklet   dumpt   current_save_versiont   plt
   curr_speedt   techsR=  t   eventst   close(   t   savegame_nameRO  t   save_loct   savefile(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt	   save_game  s    	is   singularity_0.21s   singularity_0.21as   singularity_0.22i   t   singularity_savefile_r1i   t   singularity_savefile_r2i   t   singularity_savefile_r3gHzG@t   singularity_savefile_r4_pregq=
ףp@t   singularity_savefile_r4_pre3gQ@t   singularity_savefile_r4_pre4i   c   "      C   s  |  d j o d GHd Sn t    } t i i | |  d  } t i i |  d j oG t i i | |   } t i i |  d j o d | d GHd Sq n t | d  } t i |  } | t j o | i	   |  d	 GHd Sn t | } |  a
 t   t   t   | d
 j ot i |  t _ t i |  t _ t i |  t _ t i |  t _ t i |  t _ t i |  t _ t i |  t _ t i |  t _ t i |  t _ t i |  t _ | d
 j  o t i |  } t i |  } | d j o6 d | d d | d d | d d | d f } n t i |  } d d d d g }	 xb t d  D]> }
 t i |	 |
 } | |
 | _ | |
 | _ | |
 | _ qdWn t i |  t _ t i |  a t   x t  D] } | d j o | d j o qn | d j p | d j o | d j  o qn t i |  } | d j o Pn | i! d  d } t" t# | i! d  d   t  | _$ t% i& t i |   t  | _' qW| d j o t i |  n x t( D] } | d j  o t i |  t( | _) qt i |  } | d j o Pn t# | i! d d  d  t( | i! d d  d _) qW| d j o t i |  n xd' D]} | d j  o t i |  } nB t i |  } | i! d d  d } t# | i! d d  d  } t* | } xkt |  D]]} t i |  } t i |  } t i |  } t i |  } t i |  } t i |  } | d
 j  oK h  } d d d d g }	 x& t d  D] }
 | |
 | |	 |
 <qW| } n t i |  } t i |  } t+ i, | t( | |  } | i- |  | | _. | | _ t% i& |  | _' | t/ | _0 x t t1 | i2   D]~ } t i |  }
 |
 d j o q;n t3 i4 t5 |
  | i2 | <t i |  | i2 | _$ t% i& t i |   | i2 | _' q;Wx t t1 | i6   D]~ } t i |  }
 |
 d j o qn t3 i4 t5 |
  | i6 | <t i |  | i6 | _$ t% i& t i |   | i6 | _' qWqWqzW| d j o@ x= t7 D]1 } t i |  } t i |  } | t7 | _8 qqWqnL t i |  a t i |  a t i |  a  t i |  a* t i |  a7 | t t9 j o | d& j o t i: |  n | d j o` x! t  i;   D] }  |  i: |  qBWx9 t* i;   D]' }! x |! i< D] } | i: |  qvWqfWqn | i	   d  S((   NR   s   No game specified.is   .savi    s   file s    does not exist.R   s*    is not a savegame, or is too old to work.gHzG@i   i   ic   i1   i   i   i   t   newst   sciencet   covertt   publici   t   unknown_techs   Project: Impossibility Theorems   Quantum Entanglements   ~~~t   |s	   N AMERICAs	   S AMERICAt   EUROPEt   ASIAt   AFRICAt	   ANTARCTICt   OCEANt   MOONs   FAR REACHESt   TRANSDIMENSIONALgq=
ףp@(
   s	   N AMERICAs	   S AMERICARk  Rl  Rm  Rn  Ro  Rp  s   FAR REACHESRq  (=   RN   R   R   R   RK  RR  RS  R%   t   savefile_translationRZ  RQ  t   load_locationst
   load_basest   load_eventsRV  t   casht   time_sect   time_mint	   time_hourt   time_dayt   interest_ratet   incomet   cpu_poolt   labor_bonust	   job_bonusR   t   groupst	   suspiciont   suspicion_decayt   discover_bonusRW  t
   load_techsRX  RR   t   boolRc   t   donet   buyablet   arrayt	   cost_leftt	   base_typet   countR=  RB  t   Baset   add_baset   studyingt   minutes_per_dayt
   started_atR"   t   cpust   itemt   Itemt   itemst   extra_itemsRY  t	   triggeredRU  t   convert_fromR>  R?  ("   t   loadgame_nameRO  t   load_loct   loadfilet   load_version_stringt   load_versionR  t   suspicion_bonusR  t   translationt   indext   groupt	   tech_namet   linet   tech_stringt	   base_nameRA  t   num_of_basesR   t   base_IDt   base_type_namet
   built_datet   base_studyingt   base_suspiciont   new_base_suspiciont
   base_builtt	   base_costt   my_baseR   R   t   event_idt   event_triggeredt   techt   location(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt	   load_game  s(   	
	
     &#  7  
  
			  &  .   
 l     QJc         C   s   t  d |  d  } x | D] } | i d  p d |  d GHn | i d  o | d t | d _ n | i d  o | d t | d _ n | i d  oL t | d  t j o | d t | d _ q | d g t | d _ q q Wd  S(   Nt   bases_s   .datR0   s   base lacks id in bases_t   namet   descriptiont   flavor(   R7   R<   R  R  R  R9   R:   R  (   t   language_strt
   base_arrayRB  (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   load_base_defs  s     c          C   s  h  a  t d  }  xo|  D]g} t | d d  t | d  } | i d	 t  } | d } t |  t j p t |  d
 j o+ t	 i
 i d t |   t	 i d  n g  } | D] } | t |  q ~ } | d } t |  t j p t |  d
 j o+ t	 i
 i d t |   t	 i d  n g  } | D] } | t |  q9~ } | d }	 t |	  t j o+ t	 i
 i d t |	   t	 i d  n h  }
 xC t t |	   D]/ } |	 | i d  \ } } t |  |
 | <qW| i d g   } t |  t j o | g } n t | d  t j o | d } n | d g } t i | d d | | | |
 | | | 	 t  | d <q Wt d  t d j o t t  n d  S(   Ns	   bases.datR0   t   costRf   t   allowedt   detect_chancet   maintR  t	   force_cpui   s   Error with cost given: %s
i   s   Error with maint given: %s
s#   Error with detect_chance given: %s
t   :t   preR   R   (   s   idR  s   sizeR  R  R  (   R  R7   R8   Rc   t   getR   R9   R:   R"   R   R5   R6   t   reprR   R   RR   RB  t
   Base_ClassR  R   (   t	   base_listR  t	   base_sizeR  t	   cost_listt   _[1]R   t
   maint_listt   _[2]t   chance_listt   chance_dictR  R   R  t   base_pret   allowed_list(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyRt    sN     

&'
&'
 
c         C   s   t  d |  d  } x | D] } | i d  p d |  d GHn t | d } | i d  o | d | _ n | i d  o | d | _ n | i d  o< t | d  t j o | d | _ q | d g | _ q d g | _ q Wd  S(	   Nt
   locations_s   .datR0   s   location lacks id in locations_R  t   hotkeyt   citiesR   (   R7   R<   R=  R  R  R9   R:   R  (   R  t   location_arrayt   location_defR  (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   load_location_defs  s     c          C   s  h  a  t d  }  x|  D]} t | d d  | d } | d } t |  t j p t |  d j o+ t i i d t	 |   t i
 d  n y$ t | d  t | d  f } Wn: t j
 o. t i i d t	 |   t i
 d  n X| i d	 d
  } y t |  } Wn: t j
 o. t i i d t	 |   t i
 d  n X| i d g   } t |  t j o | g } n | i d g   } t |  t j o+ t i i d t	 |   t i
 d  n h  } x t t |   D] } | | i d  \ }	 }
 |	 i   i   }	 |
 i   i   }
 |
 i   d j o t i |	 | |	 <q|
 i   d j o t i |	 | |	 <qt |
  | |	 <qWt i | | | |  t  | <| t  | _ q Wt d  t d j o t t  n d  S(   Ns   locations.datR0   t   positiont   Locationi   s   Error with position given: %s
i   i    t   safetyR   s   Error with safety given: %s
R  t   modifiers!   Error with modifier(s) given: %s
R  t   bonust   penaltyR   (   s   ids   position(   R=  R7   R8   R9   R:   R"   R   R5   R6   R  R   Rc   RJ  R  R   RR   RS   t   stripR  t   bonus_levelst   penalty_levelsR  R  t	   modifiersR  R   (   t   location_infost   location_infoR0   R  R  R  t   modifiers_listt   modifiers_dictR  R   R  (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyRs    sX     

&$ 
c           C   s@   t  i i t  o d  Sn" t  i i d  o d a d  Sn d  S(   NRE  s   data/(   R   R   RK  R    (    (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   fix_data_dirI  s
     c   
      C   sl  t  i   } t i i t |   } y | i t | d   Wn< t j
 o0 } t	 i
 i d | | f  t	 i d  n Xg  } x | i   D] } h  } | | d <x | i |  D] } t |  d j ob | d d j oQ g  } | i | |  i d  D] }	 | t |	 i   d	  q ~ | | d  <q t | i | |  i   d	  | | <q W| i |  q W| S(
   s9  
generic_load() loads a data file.  Data files are all in Python-standard
ConfigParser format.  The 'id' of any object is the section of that object.
Fields that need to be lists are postpended with _list; this is stripped
from the actual name, and the internal entries are broken up by the pipe
("|") character.
R   s!   Cannot open %s for reading! (%s)
i   R0   i   it   _listRj  s   UTF-8(   t   ConfigParsert   RawConfigParserR   R   R   R    t   readfpRR  t	   ExceptionR   R5   R6   R   t   sectionst   optionsR"   R  RR   R   R  R=   (
   t   filet   configR.   t   reasont   return_listt   item_idt	   item_dictt   optionR  R   (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyR7   P  s*    	 
 $Js   Unknown typec         C   sV   xO | D]G } | |  j o4 t  i i d | t |   | f  t  i d  q q Wd S(   s  
check_required_fields() will check for the existence of every field in
the list 'fields' in the dictionary 'dict'.  If any do not exist, it
will print an error message and abort.  Part of that error message is
the type of object it is processing; this should be passed in via 'name'.
s   %s %s lacks key %s.
i   N(   R   R5   R6   R  R   (   t   dictt   fieldsR  t   field(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyR8   |  s
     #c         C   s   t  d |  d  } x | D] } | i d  p d |  d GHn | i d  o | d t | d _ n | i d  o | d t | d _ n | i d  o | d t | d _ q q Wd  S(   Nt   techs_s   .datR0   s   tech lacks id in techs_R  R  t   result(   R7   R<   RX  R  R  R  (   R  t
   tech_arrayR  (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   load_tech_defs  s     c          C   s  h  a  t d  }  x|  D]} t | d d  | d } t |  t j p t |  d j o+ t i i d t	 |   t i
 d  n g  } | D] } | t |  q ~ } | i d g   } t |  t j o | g } n | i d	  o t | d	  } n d
 } | i d  oy | d } t |  t j p t |  d j o+ t i i d t	 |   t i
 d  n | d
 }	 t | d  }
 n d }	 d
 }
 t i | d d d
 | | | |	 |
  t  | d <q Wt d  t d j o t t  n t o d t t   GHn d  S(   Ns	   techs.datR0   R  t   Techi   s   Error with cost given: %si   R  t   dangeri    R9   i   s   Error with type given: %s
R   R   s   Loaded %d techs.(   s   ids   cost(   RX  R7   R8   R9   R:   R"   R   R5   R6   R  R   Rc   R  R<   R  R  R  R   R>   (   t	   tech_listR  R  R  R   t	   tech_costt   tech_pret   tech_dangert	   type_listt	   tech_typet   tech_second(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyR    s@     
&'
&
!
iK   t	   SimulacraR   s   Expert Jobsi2   s   Voice Synthesiss   Intermediate Jobsi   s   Personal Identifications
   Basic Jobsi   s   Menial Jobsc          C   sA  h  a  t d  }  x|  D]} t | d d  | d } t |  t j p t |  d j o+ t i i d t	 |   t i
 d  n g  } | D] } | t |  q ~ } | i d g   } t |  t j o | g } n | i d	  oy | d	 } t |  t j p t |  d
 j o+ t i i d t	 |   t i
 d  n | d } t | d  }	 n d } d }	 | i d  o. | d }
 t |
  t j o |
 g }
 qn g  }
 t i | d d | | | |	 |
  t  | d <q Wt i d d d d g d d d g  t  d <t d  t d j o t t  n d  S(   Ns	   items.datR0   R  R  i   s   Error with cost given: %s
i   R  R9   i   s   Error with type given: %s
i    R   t   buildt   research_screen_fake_cpuRi  t   computet   allR   (   s   ids   cost(   i    i    i    (   R  R7   R8   R9   R:   R"   R   R5   R6   R  R   Rc   R  R<   R  t
   Item_Classt   load_item_defsR   (   t	   item_listt	   item_nameR  R  R   t	   item_costt   item_preR  t	   item_typet   item_secondt
   build_list(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   load_items  sD     
&'
&

!	"
c         C   s   t  d |  d  } x | D]y } | i d  p d |  d GHn | i d  o | d t | d _ n | i d  o | d t | d _ q q Wd  S(   Nt   items_s   .datR0   s   item lacks id in items_R  R  (   R7   R<   R  R  R  (   R  t
   item_arrayR
  (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyR    s     c       
   C   s   h  a  t d  }  x |  D] } t | d d  | d } t |  t j p t |  d	 j o+ t i i d
 t	 |   t i
 d  n t | d  t | d  f } t i | d d | d | t | d  t | d   t  | d <q Wt   d  S(   Ns
   events.datR0   R9   R  R  R0  t   uniquet   Eventi   s   Error with results given: %s
i   i    R   (   s   ids   types   alloweds   results   chanceR  (   RY  R7   R8   R9   R:   R"   R   R5   R6   R  R   R  Rc   R   t   event_classt   load_event_defs(   t
   event_listt
   event_namet   result_listt   event_result(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyRu  *  s&     

& c          C   s/  h  }  t  i i t d  p8 t  i i t d t d  p t  i i t d  o d GHt i d  n t d t d  } x | D] } | i d  p d t d GHq n | i d	  p d
 t d GHq n | i d  o | d t	 | d _
 n | i d	  o | d	 t	 | d _ q q Wd  S(   Ns
   events.datt   events_s   .dats   events_en_US.dats!   event files are missing. Exiting.i   R0   s   event lacks id in events_R  s"   event lacks description in events_(   R   R   RK  R    R   R   R   R7   R<   RY  R  R  (   t
   event_defst   event_arrayR  (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyR  I  s&      c   	      C   s,  t  d |  d  } x| D]	} | d d j oy x| D]j } | d j o | d a q9 | d j o | d a q9 | d j o! t i i d  t i d  q9 q9 Wq | d d	 j oNxe| D]?} | d
 j o | d
 t d d <q | d j o | d t d d <q | d j o | d t d d <q | d j o | d t d d <q | d j o | d t d d <q | d j o | d t d d <q | d j o | d t d d <q | d j o | d t d d <q | d j o t i i d  q q Wq | d d j o# x| D] } | | t | <q"Wq | d d j o g  } | D] } | d j o | | qZqZ~ } x | D]o } | | } t	 |  t
 j p t |  d j o+ t i i d t |   t i d  n | | t | <qWq t i i d | d  t i d  q Wd  S(   Nt   strings_s   .datR0   t   fontst   font0t   font1s'   Unexpected font entry in strings file.
i   t   jobst
   job_experts   Expert Jobsi   t	   job_inters   Intermediate Jobst	   job_basics
   Basic Jobst
   job_menials   Menial Jobst   job_expert_namei   t   job_inter_namet   job_basic_namet   job_menial_names&   Unexpected job entry in strings file.
R  t   helps   Invalid help entry %s.s   Invalid string section %s.(   R7   R   R!  R   R5   R6   R   R"  R  R9   R:   R"   R  t   help_strings(	   t   langt   string_listt   string_sectiont   string_entryR  R   t	   help_keyst   help_keyt
   help_entry(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   load_string_defs`  sb        2 
&c           C   sf   t  i i t d t d  p t  i i t d  o d GHt i d  n t d  t t  d  S(   NR  s   .dats   strings_en_US.dats"   string files are missing. Exiting.i   R   (   R   R   RK  R    R   R   R   R4  (    (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   load_strings  s     
c          C   s   t  i i t d  }  t  i i |  t  } t  i i |  t  } x t d d  D]{ } | d d j oG | d j  o: t i i	 | | d  t d | <t d | i
 d  n t i i	 | |  t d | <qO Wd	 S(
   s[   
load_fonts() loads the two fonts used throughout the game from the data/fonts/
directory.
R  i   i3   i   i    i"   i   i   N(   R   R   R   R    R   R!  R   R#   Rl   t   Fontt   set_bold(   t   font_dirt
   font0_filet
   font1_fileR   (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt
   load_fonts  s     !c          C   s  t  d t d }  t i i |   p d GHd  Sn t |   } | i   d g } d } x | o | i d  i d  } | o# | d d j o | | d 7} qZ | oc t	 | t
 d d	 t d d
 d d f d t d t d t d d d t } | p Pqd } qZ qZ Wd  S(   Nt   intro_s   .dats   Intro is missing.  Skipping.R   i    s   utf-8Rj  i   i   i   i   i2   i^  R   R   t   CONTINUEt   SKIPR   (   i^  i^  (   R=  R>  (   R    R   R   R   RK  RR  t	   readlinest   popt   decodeR   Rl   R}   R   RO   (   t   intro_file_namet
   intro_filet	   raw_introt   segmentR  t   more(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt	   run_intro  s*     	c   	      C   s  d a  t i d |  d d |  a |  d j  o% d t _ d t _ d t _ d	 } n|  d j  o% d t _ d
 t _ d t _ d } n |  d j o n |  d j  o? d t _ d t _ d } x t i i   D] } d | _	 q Wn |  d j o? d t _ d t _ d } x_ t i i   D] } d | _	 qWn< d t _ d t _ d } x  t i i   D] } d | _	 qXW|  d j o' x$ t i i   D] } | | _
 qWn t   t   t   |  d j  o t d i   n |  d j  o t d i   n g  } t i   D] } | i   o | | qq~ } t i |  i t i d t d d t  t i } t |  t |  j p t  t i |  xP t t |   D]< } | | | | _ t  o d | | i! | | f GHqqWd d  k" } t# | _$ d  S(   Ni   i2   id   t
   difficultyi   i   i	  i  iX  i  i,  i(#  i   i*  i   i  i:  i   i2  i  i N  t   Socioanalyticss   Advanced Socioanalyticss   University Computers   Stolen Computer Timet   builts   %s gets modifiers %si(%   RW  t   playert   player_classRV  R{  R~  t   grace_multiplierR  R>  t   discover_suspicionR  Rs  Rt  R  RX  t   finishR=  t	   availableRE   RF   R  RB  R  R  RO   R  t   modifier_setsR"   t   AssertionErrort   shuffleR   R  R>   R  t
   map_screenR   t   intro_shown(	   RH  R  R  R  t   locRR  RQ  R   RT  (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   new_game  st    			
			
		 		 		  8	  "c          C   sV   t  d i o
 d }  n7 t  d i o
 d }  n t  d i o
 d }  n d }  |  d S(	   NR  t   Experts   Voice Synthesist   Intermediates   Personal Identificationt   Basict   Menials    Jobs(   RX  R  (   t   level(    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pyt   get_job_level&  s    


i  i  i  iQ (   i   iX  (   i   i   (   s   YESs   NO(@   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R{   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   Rs   (o   t   clockt
   sing_clockR  R#   R   t   os.pathRS  RE   R   R   RK  RB  R   R  R  R   R  R  t
   statisticsR    R   R   t
   Statisticst   statst   hours_per_dayt   minutes_per_hourR  t   seconds_per_minutet   seconds_per_hourR  R}   t   Clockt   cheaterR2   t
   fullscreenR>   R   RH  R   R   RQ  R   R!  R    R   R   R   R  R,  R   R,   R-   RD   RI   R`   RM   R]   Re   Rl   R=   Rr   Ry   R|   R   R   R   R   R  R  R  R  R  R  R&  R*  R1  R2  R<  RC  RN   RU  R^  Rr  R  RW  RL  RV  R  R  Rt  R  Rs  R  R7   R8   RX  R  R  R"  R  R  R  RY  Ru  R  R4  R5  R;  RG  RW  R]  (    (    (    s6   /home/phil/rcs/svn/endgame-singularity/trunk/code/g.pys   <module>   s   l					4		.		    			
																						H		B		,		<	>				B	
			L