Ñò
\{’Pc           @   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 l Z d  d k l Z l	 Z	 d  d k
 Te o d  d k l Z n d Z e d Z d Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z e i Z d e Z e d Z e i e ƒ Z d d. d „  ƒ  YZ  d „  Z! d „  Z" e# d „ Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* d  „  Z+ d! „  Z, d" „  Z- d# „  Z. d$ „  Z/ d% „  Z0 d& „  Z1 d' „  Z2 d( „  Z3 d) „  Z4 d* „  Z5 d+ „  Z6 d, „  Z7 d- „  Z8 d S(/   iÿÿÿÿN(   t    EFFECT_MATERIAL_INDEXES_BY_NAMES(   t	   IS_CLIENTt   DESTRUCTIBLE_MATKIND(   t   *(   t   EffectsListg      @g      à?s   scripts/destructibles.xmls!   scripts/destructibles_effects.xmliG   i    i   i   i   t	   destroyedt	   undamagedi'  g{®Gáz„?g       @g      @t   DestructiblesCachec           B   s_   e  Z d  „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   c         C   sš  t  o: t i t ƒ } | p t d t ‚ n t | ƒ |  _ n t i t ƒ } | p t d t ‚ n | i d ƒ |  _	 | i d ƒ |  _
 g  } x4 | d i ƒ  D]" } |  i | ƒ } | i | ƒ q£ Wx4 | d i ƒ  D]" } |  i | ƒ } | i | ƒ qÚ Wx4 | d i ƒ  D]" } |  i | ƒ } | i | ƒ qWx4 | d i ƒ  D]" } |  i | ƒ } | i | ƒ qHW| |  _ t d „  t | ƒ Dƒ ƒ |  _ d  S(	   Ns   Fail to read '%s't   defaultLifetimeEffectChancet   unitVehicleMasst   fragilest   fallingAtomst   treest
   structuresc         s   s)   x" |  ] \ } } | d  | f Vq Wd S(   t   filenameN(    (   t   .0t   it   desc(    (    s$   scripts/common/DestructiblesCache.pys	   <genexpr>¢   s   	 (   R   t   ResMgrt   openSectiont   DESTRUCTIBLES_EFFECTS_FILEt	   Exceptiont   _readDestructiblesEffectst   _DestructiblesCache__effectst   DESTRUCTIBLES_CONFIG_FILEt	   readFloatt0   _DestructiblesCache__defaultLifetimeEffectChancet$   _DestructiblesCache__unitVehicleMasst   valuest    _DestructiblesCache__readFragilet   appendt$   _DestructiblesCache__readFallingAtomt   _DestructiblesCache__readTreet"   _DestructiblesCache__readStructuret   _DestructiblesCache__descst   dictt	   enumeratet   _DestructiblesCache__descIDs(   t   selft   sect   descst
   fragileSecR   t
   fallingSect   treeSect	   structSec(    (    s$   scripts/common/DestructiblesCache.pyt   __init__   s:        	c         C   s   |  i  S(   N(   R   (   R&   (    (    s$   scripts/common/DestructiblesCache.pyR	   ¥   s    c         C   s&   | t  |  i ƒ j  o |  i | Sd  S(   N(   t   lenR"   t   None(   R&   t   descID(    (    s$   scripts/common/DestructiblesCache.pyt   getDescByID«   s    c         C   s   |  i  i | ƒ S(   N(   R%   t   get(   R&   R   (    (    s$   scripts/common/DestructiblesCache.pyt   getDescIDByFilename²   s    c         C   s,   |  i  | ƒ } | d  j	 o |  i | Sd  S(   N(   R3   R/   R"   (   R&   R   t   id(    (    s$   scripts/common/DestructiblesCache.pyt   getDescByFilename·   s    c             s2  | i  d ƒ } g  ‰ h  } xI| d i ƒ  D]7} h | i d ƒ d 6} | i  d ƒ } t | | ƒ } | o | \ } }	 }
 } n q, t i |	 ƒ } | d  j	 o | | d <n t d | ƒ t o� t	 | | d |  i
 d | ƒ t	 | | d	 |  i
 d | ƒ t	 | | d
 |  i
 d | ƒ | i  d ƒ | d <| i d ƒ | d <n ˆ i |
 ƒ | | f | |
 <q, Wt i t i } t ˆ ƒ | j o t d | ƒ ˆ |  ‰ n ˆ i ƒ  h  } h  } t i ‰  t i } g  } x‚ t ˆ ƒ D]t \ } }
 | |
 \ } } | | } | | d <ˆ  | } | i | ƒ | | | <t ‡  ‡ f d †  | Dƒ ƒ | | <qáWh  } xÉ | i ƒ  D]» } t ƒ  } | g } xr t | ƒ d j o^ | i ƒ  } | | j o q‡n | i | ƒ | i | ƒ } | d  j o q‡n | | 7} q‡W| i | ƒ t | ƒ d j o | | | <qlqlWh g  t 6| t 6} | i d ƒ o¶ x³ | d i ƒ  D]� } | i  d ƒ i ƒ  } | i  d ƒ i d ƒ } g  } xW | D]O } t | | ƒ } | o | \ } }	 }
 } n q | i ˆ i |
 ƒ ˆ  ƒ q W| | | <q`Wn h | d 6t  d 6| d 6| d 6| d 6} | S(   NR   t   modulest   healtht   matNamet   effectMtrlIdxs%   Wrong effect material in structure %st	   ramEffectR   t	   hitEffectt   decayEffectt   effectHPt   effectScalesL   Number of modules in structure %s exceeds destructibles material kinds ranget   destroyedMatc         3   s&   x |  ] } ˆ i  | ƒ ˆ  Vq Wd  S(   N(   t   index(   R   R4   (   t   matkindNMint   ids(    s$   scripts/common/DestructiblesCache.pys	   <genexpr>ð   s   	 i    t   statest   namet   destroyedMaterialst    t   typet   destroyDependst   statePresets(!   t
   readStringR   t   readIntt   _parseMaterialNameR    R2   R/   t	   LOG_ERRORR   t   _readAndMapEffectR   R   R   R   t
   NORMAL_MAXt
   NORMAL_MINR.   t   sortt   DAMAGED_MINR$   t   tuplet   iterkeyst   sett   popt   addt   removet   DESTR_STATE_NAME_UNDAMAGEDt   DESTR_STATE_NAME_DESTROYEDt   has_keyt   stript   splitR@   t   DESTR_TYPE_STRUCTURE(    R&   R,   R   t   idMapt	   moduleSect   moduleR8   t   resRG   t   surfaceR4   t   dependsR9   t   destrMatkindCntt   mapR6   t   matkindDMint   matkindsNormalR   R?   t	   normalMatRH   t   roott   rootDependst   stackt   curRI   t   stateSecRD   t   matNamest   matKindsR   (    (   RA   RB   s$   scripts/common/DestructiblesCache.pyt   __readStructure¾   s¢     
		 



' 		   

c         C   s  | i  d ƒ } | i d d ƒ } h | d 6| i d ƒ d 6| d 6t d 6} | i  d ƒ } | o= t | | ƒ } t i | ƒ } | d  j	 o | | d <qŸ n t od t	 | | d |  i
 d	 | ƒ t	 | | d
 |  i
 d	 | ƒ | i  d ƒ | d <| i d ƒ | d <n | S(   NR   t   kineticDamageCorrectiong        R7   RG   R8   R9   t   effectR
   R<   R=   R>   (   RJ   R   RK   t   DESTR_TYPE_FRAGILEt   _parseFragileMaterialNameR    R2   R/   R   RN   R   (   R&   R)   R   Rr   R   R8   Rc   R9   (    (    s$   scripts/common/DestructiblesCache.pyt   __readFragile   s$    

c         C   s  | i  d ƒ } | i d d ƒ } h | d 6| i d ƒ d 6| i d ƒ d 6| d 6t d 6} t | ƒ } | i | ƒ t o� t | | d |  i d | ƒ t | | d	 |  i d | ƒ t | | d
 |  i d | ƒ | i	 d ƒ o | i d ƒ | d <q|  i
 | d <n | S(   NR   Rr   g        R7   t   densityRG   t   fractureEffectR   t   touchdownEffectt   lifetimeEffectt   lifetimeEffectChance(   RJ   R   RK   t   DESTR_TYPE_TREEt   _readDestructiblePhysicParamst   updateR   RN   R   R[   R   (   R&   R+   R   Rr   R   t
   physParams(    (    s$   scripts/common/DestructiblesCache.pyt
   __readTree9  s"    

c         C   s  | i  d ƒ } | i d d ƒ } h | d 6| i d ƒ d 6| d 6t d 6} t | ƒ } | i | ƒ t o¢ t | | d |  i d | ƒ t | | d |  i d | ƒ t | | d	 |  i d | ƒ | i	 d
 ƒ o t
 i d
 ƒ | d
 <n |  i | d
 <| i d ƒ | d <n | S(   NR   Rr   g        R7   RG   Rx   R   Ry   Rz   R{   R>   (   RJ   R   RK   t   DESTR_TYPE_FALLING_ATOMR}   R~   R   RN   R   R[   R+   R   (   R&   R*   R   Rr   R   R   (    (    s$   scripts/common/DestructiblesCache.pyt   __readFallingAtomR  s"    

(   t   __name__t
   __module__R-   t   propertyR	   R1   R3   R5   R!   R   R    R   (    (    (    s$   scripts/common/DestructiblesCache.pyR   |   s   	&				b		c         C   sE   y |  i  d ƒ } | d } Wn! t d |  | f ƒ d  } n X| S(   Nt   _i   s,   Fail to parse material name %s in fragile %s(   R]   RM   R/   (   R8   R   t   arrRb   (    (    s$   scripts/common/DestructiblesCache.pyRu   l  s    
c         C   s„   y\ |  i  d ƒ } | d } | d } t | d ƒ } t t | d ƒ } | | | | f } Wn! t d |  | f ƒ d  } n X| S(   NR†   i    i   i   i   s.   Fail to parse material name %s in structure %s(   R]   t   intRf   RM   R/   (   R8   R   R‡   RG   Rc   R4   Rd   Rb   (    (    s$   scripts/common/DestructiblesCache.pyRL   w  s    


c         C   s�   | i  | ƒ } | p$ | o t d | | f ƒ d  Sn t i | ƒ d j o d  S| i | ƒ } | d  j o | o t d | ƒ n d  S| |  | <d  S(   Ns   Failed to read %s name in %st   nones$   Destructibles effect %s is not found(   RJ   t   LOG_WARNINGt   stringt   lowerR2   R/   RM   (   t   cfgR'   t	   effectKeyt   effectst   destrFilenamet   needLogErrorst
   effectNameRs   (    (    s$   scripts/common/DestructiblesCache.pyRN   †  s    	c   	      C   s”   h  } x‡ |  i  ƒ  D]y \ } } h  } xZ | i  ƒ  D]L \ } } g  } x' | i ƒ  D] } | i t | ƒ ƒ qQ Wt | ƒ | | <q2 W| | | <q W| S(   N(   t   itemsR   R   t   _readStagesAndEffectsRS   (	   R'   R�   t	   groupNamet   groupSect   groupEffectst   effNamet   effSect   variantst   varSec(    (    s$   scripts/common/DestructiblesCache.pyR   �  s       c         C   s¾   t  ƒ  } g  } |  d } xj | i ƒ  D]\ } | | j o t d | |  i f ‚ n | i | ƒ } | i | ƒ | i | | f ƒ q& W|  d } y t i | ƒ } Wn t ƒ  n X| | f S(   Nt   stagess-   Duplicated stage %s in %s destructible effectR�   (	   RU   t   keysR   RD   R   RW   R   R   t   LOG_CURRENT_EXCEPTION(   t   sectiont   stagesNamesRœ   t	   stagesSect   snamet   durationt
   effectsSecR�   (    (    s$   scripts/common/DestructiblesCache.pyR”   ®  s     	
 
 c         C   sj   t  |  d d ƒ } h | d d 6| d d 6| d d 6| d	 d
 6| d d 6| d d 6| d d 6} | S(   Nt   physicParamsi   i    t   massi   t   heighti   t   springAnglei   t   springStiffnesi   t   springResisti   t	   airResisti   t	   buryDepth(   t   _readFloatArray(   RŸ   t   paramsR�   (    (    s$   scripts/common/DestructiblesCache.pyR}   Ã  s    c         C   sU   |  i  d ƒ } | i ƒ  } t | ƒ | j o t d |  i ‚ n t t t | ƒ ƒ S(   Nt    s)   Error reading float array from section %s(   RJ   R]   R.   R   RD   RS   Rf   t   float(   R'   t   countt   arrayStrt   strArr(    (    s$   scripts/common/DestructiblesCache.pyR­   Ò  s
    c         C   sU   |  i  d ƒ } | i ƒ  } t | ƒ | j o t d |  i ‚ n t t t | ƒ ƒ S(   NR¯   s'   Error reading int array from section %s(   RJ   R]   R.   R   RD   RS   Rf   Rˆ   (   R'   R±   R²   R³   (    (    s$   scripts/common/DestructiblesCache.pyt   _readIntArrayÚ  s
    c         C   sF   |  i  d ƒ } | i ƒ  } t | ƒ | j o t d |  i ‚ n | S(   NR¯   s'   Error reading int array from section %s(   RJ   R]   R.   R   RD   (   R'   R±   R²   R³   (    (    s$   scripts/common/DestructiblesCache.pyt   _readStringArrayâ  s
    c         C   s   t  t i |  |  | ƒ ƒ S(   N(   Rˆ   t   matht   ceil(   t   scalet	   refHealth(    (    s$   scripts/common/DestructiblesCache.pyt   scaledDestructibleHealthë  s    c         C   sF   t  t |  i d ƒ ƒ } t  t |  i d ƒ ƒ } | d d >| d BS(   Ng{®Gáz„?i   i   (   Rˆ   t   roundt   xt   z(   t   positiont   chunkXt   chunkZ(    (    s$   scripts/common/DestructiblesCache.pyt   chunkIDFromChunkPositionñ  s    c         C   s?   |  d ?d d d } |  d @d d d } t  i | d | ƒ S(   Ni   i   g      Y@g      I@iÿ   i    (   t   Matht   Vector3(   t   chunkIDR¼   R½   (    (    s$   scripts/common/DestructiblesCache.pyt   controllerPositionFromChunkID÷  s    c         C   sD   t  t i |  d t ƒ ƒ } t  t i |  d t ƒ ƒ } | | f S(   Ni    i   (   Rˆ   R¶   t   floort   _INV_CHUNK_RANGE(   R¾   R¿   RÀ   (    (    s$   scripts/common/DestructiblesCache.pyt   chunkIndexesFromPositionþ  s    c         C   s   t  t |  ƒ Œ  S(   N(   t   chunkIDFromChunkIndexesRÈ   (   R¾   (    (    s$   scripts/common/DestructiblesCache.pyt   chunkIDFromPosition  s    c         C   s   |  d d >| d BS(   Ni   i   (    (   t   gridXt   gridZ(    (    s$   scripts/common/DestructiblesCache.pyRÉ     s    c         C   s   |  d ?d |  d @d f S(   Ni   i   iÿ   (    (   R4   (    (    s$   scripts/common/DestructiblesCache.pyt   chunkIndexesFromChunkID  s    c         C   s}   t  |  ƒ \ } } t |  ƒ } t t i t d | | ƒ } t t i t d | | ƒ } t i | i	 | d | i
 | ƒ S(   Ng      $@i    (   RÍ   RÅ   t   RADIUS_FOR_LOCATION_ADR¶   t   cost   PIt   sinRÂ   RÃ   R¼   R½   (   RÄ   RË   RÌ   t   post   dxt   dz(    (    s$   scripts/common/DestructiblesCache.pyt$   areaDestructiblesPositionFromChunkID  s
    c         C   st   t  | ƒ } | d j  o
 d } n | d j o
 d } n t  d | t t ƒ d } | d >| d @B} |  d >| BS(   Ni    i   g      P@i@   i   i   (   Rˆ   RÐ   t   PI_2(   t
   destrIndext   fallYawt	   fallSpeedt   discreteYawR®   (    (    s$   scripts/common/DestructiblesCache.pyt   encodeFallenColumn  s    

c         C   sA   |  d ?} |  d @} | d ?d t  t } | d @} | | | f S(   Ni   iÿ   i   g      P@i   (   RÖ   RÐ   (   t   dataR×   R®   RØ   RÙ   (    (    s$   scripts/common/DestructiblesCache.pyt   decodeFallenColumn'  s
    


c         C   sž   t  | ƒ } | d j  o
 d } n | d j o
 d } n t  d | t t ƒ d @} | d >| d @B} |  d >| B} t  d | t t ƒ d @} | d	 >| BS(
   Ni    i   g      P@i?   i   i   g      ð@iÿÿ  i   (   Rˆ   RÐ   RÖ   (   R×   RØ   t   fallPitchConstrRÙ   RÚ   R®   t   b32t   discretePitchConstr(    (    s$   scripts/common/DestructiblesCache.pyt   encodeFallenTree2  s    

c         C   sj   |  d ?} | d ?} | d @} | d ?d t  t } | d @} |  d @} | d t  t } | | | | f S(	   Ni   i   iÿ   i   g      P@i   iÿÿ  g      ð@(   RÖ   RÐ   (   RÜ   Rß   R×   R®   RØ   RÙ   Rà   RÞ   (    (    s$   scripts/common/DestructiblesCache.pyt   decodeFallenTree@  s    




c         C   s   |  d >| d >Bt  | ƒ d @BS(   Ni   i   (   Rˆ   (   t   destrIDt   matKindt   isShotDamage(    (    s$   scripts/common/DestructiblesCache.pyt   encodeDestructibleModuleK  s    c         C   s   |  d ?|  d ?d @|  d @f S(   Ni   i   i   (    (   RÜ   (    (    s$   scripts/common/DestructiblesCache.pyt   decodeDestructibleModuleP  s    (    (9   R   t   BigWorldRÂ   R¶   t	   constantsR‹   t   material_kindsR    R   R   t   debug_utilst   helpersR   t   SEARCH_AD_RADIUSRÎ   R   R   t   SPT_MATKIND_SOLIDR|   R�   Rt   R^   RZ   RY   t   STATIC_OBSTACLE_IDRÇ   t   piRÐ   RÖ   t"   FALLING_DESTRUCTIBLES_IGNORE_ANGLERÑ   t    FALLING_DESTRUCTIBLES_IGNORE_SINR   Ru   RL   t   TrueRN   R   R”   R}   R­   R´   Rµ   Rº   RÁ   RÅ   RÈ   RÊ   RÉ   RÍ   RÕ   RÛ   RÝ   Rá   Râ   Ræ   Rç   (    (    (    s$   scripts/common/DestructiblesCache.pyt   <module>   sf   

	

Hð																						