home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Scripts / GotoMapVars.py < prev    next >
Encoding:
Python Source  |  2000-10-27  |  8.9 KB  |  351 lines

  1.  
  2.  
  3. import Bladex
  4. import GameState
  5. import MemPersistence
  6. import BBLib
  7. import string
  8.  
  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.  
  16.         if not entity:
  17.             return
  18.  
  19.         import Actions
  20.  
  21.  
  22.         self.Props={}
  23.         self.Props["Life"]=entity.Life
  24.         self.Props["Level"]=entity.Level
  25.         self.Props["PartialLevel"]=entity.PartialLevel
  26.         self.Props["Energy"]=entity.Energy
  27.         
  28.         GameState.EntityPersonState.__init__(self,entity)
  29.         inv=entity.GetInventory()
  30.         self.Inventory={}
  31.         self.Inventory["Objects"]=[]
  32.         for i in range(inv.nKindObjects):
  33.             for name in Actions.GetListOfObjectsAt(inv,i):
  34.                 self.Inventory["Objects"].append(self.__GetObjAux(name))
  35.  
  36.         self.Inventory["Weapons"]=[]
  37.         for i in range(inv.nWeapons):
  38.             self.Inventory["Weapons"].append(self.__GetObjAux(inv.GetWeapon(i)))
  39.  
  40.         self.Inventory["Shields"]=[]
  41.         for i in range(inv.nShields):
  42.             self.Inventory["Shields"].append(self.__GetObjAux(inv.GetShield(i)))
  43.  
  44.         self.Inventory["Quivers"]=[]
  45.         for i in range(inv.nQuivers):
  46.             self.Inventory["Quivers"].append(self.__GetObjAux(inv.GetQuiver(i)))
  47.  
  48.         self.Inventory["Keys"]=[]
  49.         for i in range(inv.nKeys):
  50.             self.Inventory["Keys"].append(self.__GetObjAux(inv.GetKey(i)))
  51.  
  52.         self.Inventory["SpecialKeys"]=[]
  53.         for i in range(inv.nSpecialKeys):
  54.             self.Inventory["SpecialKeys"].append(self.__GetObjAux(inv.GetSpecialKey(i)))
  55.  
  56.         self.Inventory["Tablets"]=[]
  57.         for i in range(inv.nTablets):
  58.             self.Inventory["Tablets"].append(self.__GetObjAux(inv.GetTablet(i)))
  59.  
  60.         self.Inventory["InvLeft"]=self.__GetObjAux(entity.InvLeft)
  61.         self.Inventory["InvLeft2"]=self.__GetObjAux(entity.InvLeft2)
  62.         #Avoid to carry standard objects to another map( chairs and similars)
  63.         if Actions.IsRightHandWeaponObject(entity.Name)==0:
  64.             print "Not taking right hand object to next map cause it┤s not a weapon!"
  65.             self.Inventory["InvRight"]=None
  66.         else:
  67.             self.Inventory["InvRight"]=self.__GetObjAux(entity.InvRight)
  68.         self.Inventory["InvLeftBack"]=self.__GetObjAux(entity.InvLeftBack)
  69.         self.Inventory["InvRightBack"]=self.__GetObjAux(entity.InvRightBack)
  70.  
  71.  
  72.     def __GetBOD(self,ent_kind):
  73.         RM=BBLib.GetResourceManager()
  74.         for i in range(RM.NResources(BBLib.B_CID_OBJDSCR)):
  75.             if RM.IsResourceLoaded(BBLib.B_CID_OBJDSCR,i):
  76.                 if RM.GetResourceName(BBLib.B_CID_OBJDSCR,i)==ent_kind:
  77.                     return RM.GetResourceFile(BBLib.B_CID_OBJDSCR,i)
  78.         return None
  79.  
  80.     def __GetObjAux(self,obj):
  81.         if not obj:
  82.             return None
  83.         objKind=Bladex.GetEntity(obj).Kind
  84.         return (obj,objKind,self.__GetBOD(objKind))
  85.  
  86.  
  87. ##    def SaveInventory(self,file_name):
  88. ##        f=open('../../Save/'+file_name,'wt')
  89. ##        p=cPickle.Pickler(f)
  90. ##        temp={}
  91. ##        temp["Life"]=self.Props["Life"]
  92. ##        temp["Level"]=self.Props["Level"]
  93. ##        temp["PartialLevel"]=self.Props["PartialLevel"]
  94. ##
  95. ##        p.dump((self.CreationProps,temp,self.Inventory))
  96. ##        f.close()
  97.  
  98.  
  99.     def GetProps(self):
  100.         temp={}
  101.         temp["Life"]=self.Props["Life"]
  102.         temp["Level"]=self.Props["Level"]
  103.         temp["PartialLevel"]=self.Props["PartialLevel"]
  104.         temp["Energy"]=self.Props["Energy"]
  105.  
  106.         return (self.CreationProps,temp,self.Inventory)
  107.  
  108.  
  109. def CreateMainCharWithProps(props):
  110.     CreationProps=props[0]
  111.     Props=props[1]
  112.     Inventory=props[2]
  113.  
  114.     import Basic_Funcs
  115.     import AniSound
  116.     import Reference
  117.     import Sparks
  118.     import Breakings
  119.     import ItemTypes
  120.     import Actions
  121.  
  122.  
  123.     char=Bladex.CreateEntity("Player1",CreationProps["Kind"],0,0,0,"Person")
  124.     char.Data=Basic_Funcs.PlayerPerson(char)
  125.     inv=char.GetInventory()
  126.     AniSound.AsignarSonidosCaballero('Player1')
  127.  
  128.     char.Level=Props["Level"]
  129.     char.PartialLevel=Props["PartialLevel"]
  130.     char.Life=Props["Life"]
  131.     char.Energy=Props["Energy"]
  132.  
  133.     for i in Inventory["Objects"]:
  134.         GameState.CreateEntAux(i,"Physic")
  135.         Actions.ExtendedTakeObject(inv,i[0])
  136.  
  137.     for i in Inventory["Weapons"]:
  138.         obj=GameState.CreateEntAux(i,"Weapon")
  139.         object_flag=Reference.GiveObjectFlag(i[0])
  140.         if object_flag == Reference.OBJ_BOW:
  141.             inv.AddBow(i[0])
  142.         else:
  143.             flag=Reference.GiveWeaponFlag(i[0])
  144.             inv.AddWeapon(i[0],flag)
  145.  
  146.         Breakings.SetBreakableWS(i[0])
  147.  
  148.     for i in Inventory["Shields"]:
  149.         GameState.CreateEntAux(i,"Weapon")
  150.         inv.AddShield(i[0])
  151.         #Para que saque chispas!!!
  152.         Sparks.MakeShield(i[0])
  153.         Breakings.SetBreakableWS(i[0])
  154.  
  155.     for i in Inventory["Quivers"]:
  156.         obj=GameState.CreateEntAux(i,"Weapon")
  157.         ItemTypes.ItemDefaultFuncs(obj)
  158.         inv.AddQuiver(i[0])
  159.  
  160.     for i in Inventory["Keys"]:
  161.         GameState.CreateEntAux(i,"Physic")
  162.         inv.AddKey(i[0])
  163.  
  164.     for i in Inventory["SpecialKeys"]:
  165.         GameState.CreateEntAux(i,"Physic")
  166.         inv.AddSpecialKey(i[0])
  167.  
  168.     for i in Inventory["Tablets"]:
  169.         GameState.CreateEntAux(i,"Physic")
  170.         inv.AddTablet(i[0])
  171.  
  172.     if Inventory["InvLeft"]:
  173.         GameState.CreateEntAux(Inventory["InvLeft"],"Physic")
  174.         inv.LinkLeftHand(Inventory["InvLeft"][0])
  175.  
  176.     if Inventory["InvLeft2"]:
  177.         GameState.CreateEntAux(Inventory["InvLeft2"],"Physic")
  178.         inv.LinkLeftHand2(Inventory["InvLeft2"][0])
  179.  
  180.     if Inventory["InvRight"]:
  181.         GameState.CreateEntAux(Inventory["InvRight"],"Physic")
  182.         inv.LinkRightHand(Inventory["InvRight"][0])
  183.  
  184.     if Inventory["InvRightBack"]:
  185.         GameState.CreateEntAux(Inventory["InvRightBack"],"Physic")
  186.         inv.LinkRightBack(Inventory["InvRightBack"][0])
  187.  
  188.     if Inventory["InvLeftBack"]:
  189.         GameState.CreateEntAux(Inventory["InvLeftBack"],"Physic")
  190.         inv.LinkLeftBack(Inventory["InvLeftBack"][0])
  191.  
  192.  
  193.  
  194. def RestoreMainCharState(key):
  195.   props=MemPersistence.Get(key)
  196.   if props:
  197.     CreateMainCharWithProps(props)
  198.     return 1
  199.   return 0
  200.  
  201.  
  202.  
  203. def SaveMainCharState(key):
  204.   ent_state=MainCharState('Player1')
  205.   props=ent_state.GetProps()
  206.   MemPersistence.Store(key,props)
  207.  
  208.  
  209.  
  210.  
  211.  
  212. #place in scripts
  213. VisitedMaps        = [ 0,0,0,0,
  214.                     0,0,
  215.                     0,
  216.                     0,
  217.                     0,0,0,0,0,0,0,0,0] # Maintained outside, 2DMAP
  218.  
  219. # Once a Tablet is placed on Ianna's update this array
  220. PlacedTablets    = [0,0,0,0,0,0] # Maintained Outside, 2DMAP
  221.  
  222.  
  223. # TEXT TO BE SAVED PER MAP
  224. MText    = []
  225. BaList    = []
  226. for a in range(17):
  227.     MText.append([])
  228.  
  229. # Formerly picked weapons
  230. PWeapons= []
  231.  
  232. # Formerly picked Items
  233. PItems    = []
  234.  
  235. # NOTES:
  236. # Llamar a esta funcion desde cualquier script de mapa donde se quiera aniadir texto, el formato es:
  237. # 1) primero se incluye "import GotoMapVars" en el comiezo del archivo (junto con los otros imports)
  238. # 2) Donde se haya de escribir el texto se pone:
  239. #        GotoMapVars.MapText(Numero del mapa, "el texto que se quiera.htm")
  240. def MapText(MapNum,MapTex):
  241.     if MapNum == -1:
  242.         BaList.append(MapTex)
  243.     else:
  244.         MText[MapNum - 1].append(MapTex) # Must include the -1 offset to make mappers work easier.
  245.  
  246. # Weapon is a string with the internal name of the weapon
  247. def PickedWeapon(Weapon):
  248.     PWeapons.append(Weapon)
  249.  
  250. # Item is a string with the internal name of the item
  251. def PickedItems(Item):
  252.     PItems.append(Item)
  253.  
  254.  
  255. def Set2DMapValuesAux():
  256.     return [VisitedMaps,PlacedTablets,MText,PWeapons,PItems,BaList]
  257.  
  258.  
  259. def Get2DMapValuesAux(vals):
  260.  
  261.     if vals:
  262.         global VisitedMaps
  263.         global PlacedTablets
  264.         global MText
  265.         global PWeapons
  266.         global PItems
  267.         global BaList
  268.         VisitedMaps=vals[0]
  269.         PlacedTablets=vals[1]
  270.         MText=vals[2]
  271.         PWeapons=vals[3]
  272.         PItems=vals[4]
  273.         BaList=vals[5]
  274.         return 1
  275.  
  276.     return 0
  277.  
  278.  
  279.  
  280.  
  281. def Get2DMapValues():
  282.  
  283.     print "Get2DMapValues()"
  284.     vals=MemPersistence.Get('2DMapValues')
  285.     if vals:
  286.         return Get2DMapValuesAux(vals)
  287.     else:
  288.         print "Get2DMapValues() -> can't find vals."
  289.     return 0
  290.  
  291.  
  292. def GetCarriedTablets():
  293.     a = [0,0,0,0,0,0]
  294.     for i in MemPersistence.Get('MainChar')[2]["Tablets"]:
  295.         a[string.atoi(i[0][len("tablilla")])-1] = 1
  296.  
  297.     return a
  298.  
  299.     
  300. def BeginLevel():
  301.     pj=RestoreMainCharState('MainChar')
  302.     if pj:
  303.         return Get2DMapValues()
  304.     return 0
  305.  
  306.     
  307.  
  308.  
  309. # LEVEL ENDING
  310. LevelNames = [    "barb_m1",        "ragnar_m2",    "dwarf_m3",        "ruins_m4",        "mine_m5",    "labyrinth_m6",    
  311.                 "tomb_m7",        "island_m8",    "orc_m9",        "orlok_m10",    "ice_m11",    "btomb_m12",
  312.                 "desert_m13",    "volcano_m14",    "palace_m15",    "tower_m16",    "chaos_m17"]
  313.  
  314. BackLevelNames = [ "mine_back", "labyrinth_back", "tomb_back", "ice_back", "btomb_back", "desert_back",
  315.                    "palace_back"]
  316.  
  317. def EndOfLevel():
  318.     import string
  319.     
  320.     global VisitedMaps
  321.     global BackLevelNames
  322.     
  323.     print "EndOfLevel()"
  324.  
  325.     print "Preparing main char for the travel."
  326.     import Actions
  327.     Actions.PutAllInBack("Player1")
  328.     Actions.RemoveAllKeys("Player1")
  329.     Actions.RemoveNoTravelObjects( "Player1" )
  330.  
  331.  
  332.  
  333.  
  334.     # Save lists in this file in c memory
  335.     pname = Bladex.GetCurrentMap()
  336.     name = string.lower(pname)
  337.  
  338.     if (name == "palace_m15"):
  339.         name = "palace_back"
  340.     if not(name in BackLevelNames):
  341.         iIndex = LevelNames.index(name)
  342.     else:
  343.         iIndex = BackLevelNames.index(name)
  344.         VisitedMaps[14] = 1
  345.     Bladex.SetStringValue("LastVisitedMap","M_" + str(iIndex+1))
  346.     VisitedMaps[iIndex] = 1
  347.     print iIndex
  348.     MemPersistence.Store('2DMapValues',Set2DMapValuesAux())
  349.     SaveMainCharState('MainChar')
  350.     Bladex.LoadLevel("2dMap")
  351.