home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Scripts / GotoMapVars.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-10-27  |  11.1 KB  |  315 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import Bladex
  5. import GameState
  6. import MemPersistence
  7. import BBLib
  8. import string
  9.  
  10. class MainCharState(GameState.EntityPersonState):
  11.     '''Clase para grabar el estado del jugador'''
  12.     
  13.     def __init__(self, ent_name = 'Player1'):
  14.         entity = Bladex.GetEntity(ent_name)
  15.         if not entity:
  16.             return None
  17.         
  18.         import Actions
  19.         self.Props = { }
  20.         self.Props['Life'] = entity.Life
  21.         self.Props['Level'] = entity.Level
  22.         self.Props['PartialLevel'] = entity.PartialLevel
  23.         self.Props['Energy'] = entity.Energy
  24.         GameState.EntityPersonState.__init__(self, entity)
  25.         inv = entity.GetInventory()
  26.         self.Inventory = { }
  27.         self.Inventory['Objects'] = []
  28.         for i in range(inv.nKindObjects):
  29.             for name in Actions.GetListOfObjectsAt(inv, i):
  30.                 self.Inventory['Objects'].append(self._MainCharState__GetObjAux(name))
  31.             
  32.         
  33.         self.Inventory['Weapons'] = []
  34.         for i in range(inv.nWeapons):
  35.             self.Inventory['Weapons'].append(self._MainCharState__GetObjAux(inv.GetWeapon(i)))
  36.         
  37.         self.Inventory['Shields'] = []
  38.         for i in range(inv.nShields):
  39.             self.Inventory['Shields'].append(self._MainCharState__GetObjAux(inv.GetShield(i)))
  40.         
  41.         self.Inventory['Quivers'] = []
  42.         for i in range(inv.nQuivers):
  43.             self.Inventory['Quivers'].append(self._MainCharState__GetObjAux(inv.GetQuiver(i)))
  44.         
  45.         self.Inventory['Keys'] = []
  46.         for i in range(inv.nKeys):
  47.             self.Inventory['Keys'].append(self._MainCharState__GetObjAux(inv.GetKey(i)))
  48.         
  49.         self.Inventory['SpecialKeys'] = []
  50.         for i in range(inv.nSpecialKeys):
  51.             self.Inventory['SpecialKeys'].append(self._MainCharState__GetObjAux(inv.GetSpecialKey(i)))
  52.         
  53.         self.Inventory['Tablets'] = []
  54.         for i in range(inv.nTablets):
  55.             self.Inventory['Tablets'].append(self._MainCharState__GetObjAux(inv.GetTablet(i)))
  56.         
  57.         self.Inventory['InvLeft'] = self._MainCharState__GetObjAux(entity.InvLeft)
  58.         self.Inventory['InvLeft2'] = self._MainCharState__GetObjAux(entity.InvLeft2)
  59.         self.Inventory['InvLeftBack'] = self._MainCharState__GetObjAux(entity.InvLeftBack)
  60.         self.Inventory['InvRightBack'] = self._MainCharState__GetObjAux(entity.InvRightBack)
  61.  
  62.     
  63.     def __GetBOD(self, ent_kind):
  64.         RM = BBLib.GetResourceManager()
  65.         for i in range(RM.NResources(BBLib.B_CID_OBJDSCR)):
  66.             if RM.IsResourceLoaded(BBLib.B_CID_OBJDSCR, i):
  67.                 if RM.GetResourceName(BBLib.B_CID_OBJDSCR, i) == ent_kind:
  68.                     return RM.GetResourceFile(BBLib.B_CID_OBJDSCR, i)
  69.                 
  70.             
  71.         
  72.         return None
  73.  
  74.     
  75.     def __GetObjAux(self, obj):
  76.         if not obj:
  77.             return None
  78.         
  79.         objKind = Bladex.GetEntity(obj).Kind
  80.         return (obj, objKind, self._MainCharState__GetBOD(objKind))
  81.  
  82.     
  83.     def GetProps(self):
  84.         temp = { }
  85.         temp['Life'] = self.Props['Life']
  86.         temp['Level'] = self.Props['Level']
  87.         temp['PartialLevel'] = self.Props['PartialLevel']
  88.         temp['Energy'] = self.Props['Energy']
  89.         return (self.CreationProps, temp, self.Inventory)
  90.  
  91.  
  92.  
  93. def CreateMainCharWithProps(props):
  94.     CreationProps = props[0]
  95.     Props = props[1]
  96.     Inventory = props[2]
  97.     import Basic_Funcs
  98.     import AniSound
  99.     import Reference
  100.     import Sparks
  101.     import Breakings
  102.     import ItemTypes
  103.     import Actions
  104.     char = Bladex.CreateEntity('Player1', CreationProps['Kind'], 0, 0, 0, 'Person')
  105.     char.Data = Basic_Funcs.PlayerPerson(char)
  106.     inv = char.GetInventory()
  107.     AniSound.AsignarSonidosCaballero('Player1')
  108.     char.Level = Props['Level']
  109.     char.PartialLevel = Props['PartialLevel']
  110.     char.Life = Props['Life']
  111.     char.Energy = Props['Energy']
  112.     for i in Inventory['Objects']:
  113.         GameState.CreateEntAux(i, 'Physic')
  114.         Actions.ExtendedTakeObject(inv, i[0])
  115.     
  116.     for i in Inventory['Weapons']:
  117.         obj = GameState.CreateEntAux(i, 'Weapon')
  118.         object_flag = Reference.GiveObjectFlag(i[0])
  119.         Breakings.SetBreakableWS(i[0])
  120.     
  121.     for i in Inventory['Shields']:
  122.         GameState.CreateEntAux(i, 'Weapon')
  123.         inv.AddShield(i[0])
  124.         Sparks.MakeShield(i[0])
  125.         Breakings.SetBreakableWS(i[0])
  126.     
  127.     for i in Inventory['Quivers']:
  128.         obj = GameState.CreateEntAux(i, 'Weapon')
  129.         ItemTypes.ItemDefaultFuncs(obj)
  130.         inv.AddQuiver(i[0])
  131.     
  132.     for i in Inventory['Keys']:
  133.         GameState.CreateEntAux(i, 'Physic')
  134.         inv.AddKey(i[0])
  135.     
  136.     for i in Inventory['SpecialKeys']:
  137.         GameState.CreateEntAux(i, 'Physic')
  138.         inv.AddSpecialKey(i[0])
  139.     
  140.     for i in Inventory['Tablets']:
  141.         GameState.CreateEntAux(i, 'Physic')
  142.         inv.AddTablet(i[0])
  143.     
  144.  
  145.  
  146. def RestoreMainCharState(key):
  147.     props = MemPersistence.Get(key)
  148.     if props:
  149.         CreateMainCharWithProps(props)
  150.         return 1
  151.     
  152.     return 0
  153.  
  154.  
  155. def SaveMainCharState(key):
  156.     ent_state = MainCharState('Player1')
  157.     props = ent_state.GetProps()
  158.     MemPersistence.Store(key, props)
  159.  
  160. VisitedMaps = [
  161.     0,
  162.     0,
  163.     0,
  164.     0,
  165.     0,
  166.     0,
  167.     0,
  168.     0,
  169.     0,
  170.     0,
  171.     0,
  172.     0,
  173.     0,
  174.     0,
  175.     0,
  176.     0,
  177.     0]
  178. PlacedTablets = [
  179.     0,
  180.     0,
  181.     0,
  182.     0,
  183.     0,
  184.     0]
  185. MText = []
  186. BaList = []
  187. for a in range(17):
  188.     MText.append([])
  189.  
  190. PWeapons = []
  191. PItems = []
  192.  
  193. def MapText(MapNum, MapTex):
  194.     if MapNum == -1:
  195.         BaList.append(MapTex)
  196.     else:
  197.         MText[MapNum - 1].append(MapTex)
  198.  
  199.  
  200. def PickedWeapon(Weapon):
  201.     PWeapons.append(Weapon)
  202.  
  203.  
  204. def PickedItems(Item):
  205.     PItems.append(Item)
  206.  
  207.  
  208. def Set2DMapValuesAux():
  209.     return [
  210.         VisitedMaps,
  211.         PlacedTablets,
  212.         MText,
  213.         PWeapons,
  214.         PItems,
  215.         BaList]
  216.  
  217.  
  218. def Get2DMapValuesAux(vals):
  219.     global VisitedMaps, PlacedTablets, MText, PWeapons, PItems, BaList
  220.     if vals:
  221.         VisitedMaps = vals[0]
  222.         PlacedTablets = vals[1]
  223.         MText = vals[2]
  224.         PWeapons = vals[3]
  225.         PItems = vals[4]
  226.         BaList = vals[5]
  227.         return 1
  228.     
  229.     return 0
  230.  
  231.  
  232. def Get2DMapValues():
  233.     print 'Get2DMapValues()'
  234.     vals = MemPersistence.Get('2DMapValues')
  235.     if vals:
  236.         return Get2DMapValuesAux(vals)
  237.     else:
  238.         print "Get2DMapValues() -> can't find vals."
  239.     return 0
  240.  
  241.  
  242. def GetCarriedTablets():
  243.     a = [
  244.         0,
  245.         0,
  246.         0,
  247.         0,
  248.         0,
  249.         0]
  250.     for i in MemPersistence.Get('MainChar')[2]['Tablets']:
  251.         a[string.atoi(i[0][len('tablilla')]) - 1] = 1
  252.     
  253.     return a
  254.  
  255.  
  256. def BeginLevel():
  257.     pj = RestoreMainCharState('MainChar')
  258.     if pj:
  259.         return Get2DMapValues()
  260.     
  261.     return 0
  262.  
  263. LevelNames = [
  264.     'barb_m1',
  265.     'ragnar_m2',
  266.     'dwarf_m3',
  267.     'ruins_m4',
  268.     'mine_m5',
  269.     'labyrinth_m6',
  270.     'tomb_m7',
  271.     'island_m8',
  272.     'orc_m9',
  273.     'orlok_m10',
  274.     'ice_m11',
  275.     'btomb_m12',
  276.     'desert_m13',
  277.     'volcano_m14',
  278.     'palace_m15',
  279.     'tower_m16',
  280.     'chaos_m17']
  281. BackLevelNames = [
  282.     'mine_back',
  283.     'labyrinth_back',
  284.     'tomb_back',
  285.     'ice_back',
  286.     'btomb_back',
  287.     'desert_back',
  288.     'palace_back']
  289.  
  290. def EndOfLevel():
  291.     import string
  292.     print 'EndOfLevel()'
  293.     print 'Preparing main char for the travel.'
  294.     import Actions
  295.     Actions.PutAllInBack('Player1')
  296.     Actions.RemoveAllKeys('Player1')
  297.     Actions.RemoveNoTravelObjects('Player1')
  298.     pname = Bladex.GetCurrentMap()
  299.     name = string.lower(pname)
  300.     if name == 'palace_m15':
  301.         name = 'palace_back'
  302.     
  303.     if not (name in BackLevelNames):
  304.         iIndex = LevelNames.index(name)
  305.     else:
  306.         iIndex = BackLevelNames.index(name)
  307.         VisitedMaps[14] = 1
  308.     Bladex.SetStringValue('LastVisitedMap', 'M_' + str(iIndex + 1))
  309.     VisitedMaps[iIndex] = 1
  310.     print iIndex
  311.     MemPersistence.Store('2DMapValues', Set2DMapValuesAux())
  312.     SaveMainCharState('MainChar')
  313.     Bladex.LoadLevel('2dMap')
  314.  
  315.