home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / darfuncs.py < prev    next >
Encoding:
Text File  |  2000-10-27  |  20.5 KB  |  764 lines

  1. ###########################################################################
  2. ###
  3. ###        The dark functions of hell come true in this file
  4. ###      Beaware little coder, the force keep a power inside the
  5. ###    hell and your nightmares will bless your unholly heart with 
  6. ###                       damns and doom over the
  7. ###
  8. ###                |\   /\  |\   - | |  |\|  /  /
  9. ###                | | |__| |_| |_ | |  | | |   \
  10. ###                |/  |  | |\  |  |_|  | |  \  /
  11. ###                 the cutting edge is bladeness
  12. ###
  13. ###########################################################################
  14.  
  15. import Bladex
  16. import AuxFuncs
  17. import EnemyTypes
  18. import Sparks
  19. import Actions
  20. import math
  21. import Breakings
  22. import types
  23. import Reference
  24. import Blood
  25. import SolidMask
  26. import ObjStore
  27. import GameStateAux
  28. import os
  29. import Blood
  30. import ItemTypes
  31. #------------------------------------------------------------------------#
  32. ActualLevel = "Noname"
  33. ############ Misc camera fucs ############ 
  34.  
  35. def Cafin(entity_name, camera_element, node):  
  36.   cam = Bladex.GetEntity("Camera")  
  37.  
  38.   if node==1:
  39.      cam.SType = 0
  40.      cam.ETarget = "Player1"
  41.      cam.TType = 2
  42.      cam.CameraClearPath(0)
  43.      cam.CameraClearPath(1)
  44.      
  45.   
  46.  
  47. def BackPlayer():
  48.     Cam = Bladex.GetEntity("Camera")
  49.     Cam.SetPersonView("Player1")
  50.  
  51. def ChangePointOfView(ox2, oy2, oz2, time,person="Player1"):
  52.  
  53.     cam=Bladex.GetEntity("Camera")
  54.  
  55.     ox1 = cam.Position[0]
  56.     oy1 = cam.Position[1]
  57.     oz1 = cam.Position[2]
  58.  
  59.     #Path objetivo
  60.     cam.AddCameraNode(0, time, ox1, oy1, oz1)
  61.     cam.AddCameraNode(0, time/2.0, ox2, oy2, oz2)
  62.     cam.AddCameraNode(0, time/2.0, (ox1+ox2)/2.0, (oy1+oy2)/2.0, (oz1+oz2)/2.0)
  63.     
  64.     cam.ETarget = person
  65.     cam.TType = 2
  66.  
  67.     cam.SType=1
  68.     cam.CameraStartPath(0)    
  69.     cam.ChangeNodeFunc=Cafin
  70.  
  71.  
  72. def ChangeCam(ox2, oy2, oz2,tx2,ty2,tz2, time,CafinProx):
  73.  
  74.     cam=Bladex.GetEntity("Camera")
  75.  
  76.     ox1 = cam.Position[0]
  77.     oy1 = cam.Position[1]
  78.     oz1 = cam.Position[2]
  79.     
  80.     
  81.     tx1 = cam.TPos[0]
  82.     ty1 = cam.TPos[1]
  83.     tz1 = cam.TPos[2]
  84.     
  85.     
  86.     #Path objetivo
  87.     cam.AddCameraNode(0, time, ox1, oy1, oz1)
  88.     cam.AddCameraNode(0, time/2.0, ox2, oy2, oz2)
  89.     cam.AddCameraNode(0, time/2.0, (ox1+ox2)/2.0, (oy1+oy2)/2.0, (oz1+oz2)/2.0)
  90.  
  91.     cam.AddCameraNode(1, time, tx1, ty1, tz1)
  92.     cam.AddCameraNode(1, time/2.0, tx2, ty2, tz2)
  93.     cam.AddCameraNode(1, time/2.0, (tx1+tx2)/2.0, (ty1+ty2)/2.0, (tz1+tz2)/2.0)
  94.     
  95.     cam.ETarget = "Player1"
  96.     cam.SType=1
  97.     
  98.     cam.TType=1
  99.     cam.CameraStartPath(0)    
  100.     cam.ChangeNodeFunc=CafinProx
  101.  
  102.  
  103. def InitGiroCamera():
  104.         cam=Bladex.GetEntity("Camera")
  105.         VecRot = 2*cam.TPos[0]-cam.Position[0], 2*cam.TPos[1]-cam.Position[1], 2*cam.TPos[2]-cam.Position[2]
  106.         cam.ESource = "Player1"
  107.         cam.SType   = 2
  108.         cam.TType   = 0
  109.         cam.TPos    = VecRot
  110.         
  111.         
  112. def GiraCamara(AngleVariation):
  113.         cam          = Bladex.GetEntity("Camera")
  114.         VecRot       = cam.TPos[0]-cam.Position[0], cam.TPos[1]-cam.Position[1], cam.TPos[2]-cam.Position[2]
  115.         vtpos        = VecRot[0]*math.cos(AngleVariation)-VecRot[2]*math.sin(AngleVariation), VecRot[0], VecRot[0]*math.sin(AngleVariation)+VecRot[2]*math.cos(AngleVariation)
  116.         cam.TPos     = vtpos[0]+cam.Position[0], cam.TPos[1], vtpos[2]+cam.Position[2]
  117.  
  118. ############ Deaths and limbs ############
  119.  
  120. DeathState = 0     # CARLOS : NO GRABAR ESTO, no es necesario
  121. DeathFile  = None  # CARLOS : NO GRABAR ESTO, no es necesario
  122.  
  123. def DetieneArmaMuerto(obj_name):
  124.     global DeathFile
  125.     if DeathFile:
  126.         o = Bladex.GetEntity(obj_name)
  127.         o.OnStopFunc=None
  128.         DeathFile.write("o = Bladex.CreateEntity('" +obj_name+"','"+o.Kind+"',"+str(o.Position[0])+","+str(o.Position[1])+","+str(o.Position[2])+",'Weapon')\n")
  129.         DeathFile.write("o.Orientation = "+str(o.Orientation[0])+","+str(o.Orientation[1])+","+str(o.Orientation[2])+","+str(o.Orientation[3])+"\n")
  130.         DeathFile.write("ItemTypes.ItemDefaultFuncs(o)\n\n")
  131.     
  132.     
  133. def DetieneMutilacion(obj_name):
  134.     global DeathFile
  135.     if DeathFile:
  136.         o = Bladex.GetEntity(obj_name)
  137.         o.OnStopFunc=None
  138.         DeathFile.write("\no = "+o.Data[0]+".SeverLimb("+str(o.Data[1])+")\n")
  139.         DeathFile.write("o.Stop()\n")
  140.         DeathFile.write("o.Position    = "+str(o.Position   [0])+","+str(o.Position   [1])+","+str(o.Position   [2])+"\n")
  141.         DeathFile.write("o.Orientation = "+str(o.Orientation[0])+","+str(o.Orientation[1])+","+str(o.Orientation[2])+","+str(o.Orientation[3])+"\n")
  142.     
  143.  
  144. def GrabarLaSangre(x,y,z):
  145.     global DeathFile
  146.     if DeathFile:
  147.         DeathFile.write("Bladex.CreateEntity('BloodPool','Entity Pool',"+str(x)+","+str(y)+","+str(z)+")\n")
  148.  
  149. def CloseDeathFile():
  150.     global DeathFile
  151.     if DeathFile:
  152.         print "closing 'death.py'..."
  153.         DeathFile.close()
  154.         DeathFile = None
  155.         os.rename("pak/deaths.py_","pak/deaths.py")
  156.         Blood.AfterCreateBlood = None
  157.     
  158.  
  159. def MuertoyTroceado2(name,trozos):
  160.     muertoint2=Bladex.GetEntity(name)
  161.     muertoint2.CastShadows = 0
  162.     muertoint2.SetOnFloor()
  163.     muertoint2.Life = 0
  164.     for i in trozos:
  165.         mut = muertoint2.SeverLimb(i)
  166.         if mut:
  167.             mut.Data = (muertoint2.Name,i)
  168.             mut.OnStopFunc=DetieneMutilacion
  169.  
  170. muertonum = 0
  171.     
  172.  
  173. def MuertoyTroceado(x,y,z,raze,weapon,trozos,angul=2.19288423389,MeshName=None):
  174.     global ActualLevel
  175.     global muertonum
  176.     global DeathState
  177.     global DeathFile
  178.     
  179.     if DeathState:
  180.         return
  181.  
  182.     if not DeathFile:
  183.         if "deaths.py" in os.listdir("./pak/"):
  184.             execfile("pak/deaths.py")
  185.             DeathState = 1
  186.             return
  187.         print "Creating 'deaths.py'..."
  188.         DeathFile = open("pak/deaths.py_","w")
  189.         DeathFile.write("import Bladex\nimport ItemTypes \n\n")
  190.         DeathFile.write("print 'loading deaths...'\n\n\n")
  191.         Blood.AfterCreateBlood = GrabarLaSangre
  192.  
  193.     if weapon != "" :
  194.         armamuertoint2=Bladex.CreateEntity(ActualLevel+"WeapDeath"+`muertonum`, weapon, 0, 0, 0,"Weapon")
  195.         ItemTypes.ItemDefaultFuncs(armamuertoint2)
  196.         armamuertoint2.OnStopFunc=DetieneArmaMuerto
  197.         
  198.     muertoint2=Bladex.CreateEntity(ActualLevel+"GuyInPieces"+`muertonum`, raze, x, y, z,"Person")
  199.     if MeshName:
  200.         muertoint2.SetMesh(MeshName)
  201.     muertoint2.Angle=angul
  202.     if weapon != "" :
  203.         Actions.TakeObject(muertoint2.Name, armamuertoint2.Name)
  204.         print "The guy ",muertoint2.Name," got a gun named ",armamuertoint2.Name
  205.     else:
  206.         print "The guy ",muertoint2.Name,"is armless"
  207.     EnemyTypes.EnemyDefaultFuncs(muertoint2)
  208.     #Bladex.AddScheduledFunc(Bladex.GetTime()+90.0, MuertoyTroceado2, (muertoint2.Name,trozos))
  209.     MuertoyTroceado2(muertoint2.Name,trozos)
  210.     
  211.     DeathFile.write(muertoint2.Name+" = "+"Bladex.CreateEntity('"+muertoint2.Name+"','"+muertoint2.Kind+"',"+str(muertoint2.Position[0])+","+str(muertoint2.Position[1])+","+str(muertoint2.Position[2])+",'Person'")
  212.     if MeshName:
  213.         DeathFile.write(",'"+MeshName+"')\n\n")
  214.     else:
  215.         DeathFile.write(")\n\n")
  216.         
  217.     DeathFile.write(muertoint2.Name+".Angle = "+str(angul)+"\n")
  218.     DeathFile.write(muertoint2.Name+".Life = 0\n\n")
  219.     Bladex.AddScheduledFunc(Bladex.GetTime()+60.0, CloseDeathFile, ())
  220.  
  221.     
  222.     muertonum = muertonum+1
  223.     
  224.  
  225. ############  Quake FX ############
  226.  
  227. def Let_temblOff():
  228.     cam = Bladex.GetEntity("Camera")
  229.     cam.EarthQuakeFactor = 0
  230.     cam.EarthQuake = 0
  231.  
  232. def Temblores(time,pianoforte=500):
  233.     cam = Bladex.GetEntity("Camera")
  234.     cam.EarthQuakeFactor = pianoforte
  235.     cam.EarthQuake = 1
  236.     Bladex.AddScheduledFunc(Bladex.GetTime()+time, Let_temblOff,())
  237.  
  238. ############  Max Camera Functions ############
  239.  
  240. def DetenLaCamaraDeLaConchaELaLora(Camera,frame):
  241.     import Scorer
  242.     cam = Bladex.GetEntity("Camera")
  243.     cam.SetPersonView("Player1")
  244.     cam.Cut()
  245.     Bladex.ActivateInput()
  246.     Scorer.SetVisible(1)
  247.     Bladex.SetListenerPosition(1)
  248.  
  249. def LaunchMaxCamera(CamName,Start,End,Funchi=DetenLaCamaraDeLaConchaELaLora):
  250.     import Scorer
  251.     cam = Bladex.GetEntity("Camera")
  252.     cam.SetMaxCamera(CamName,Start,End)
  253.     Scorer.SetVisible(0)
  254.     Bladex.SetListenerPosition(2)
  255.     Bladex.DeactivateInput()
  256.     cam.AddCameraEvent(-1,Funchi)
  257.  
  258. ############ Bad Guys funcs ############
  259. def HideObject(oname):
  260.     if oname:
  261.         obj = Bladex.GetEntity(oname)
  262.         obj.RemoveFromWorld()        
  263.         n_child=obj.GetNChildren()
  264.         for n in range(n_child):
  265.             HideObject(obj.GetChild(n))
  266.         
  267.  
  268. def UnhideObject(oname):
  269.     if oname:
  270.         obj = Bladex.GetEntity(oname)
  271.         obj.PutToWorld()        
  272.         n_child=obj.GetNChildren()
  273.         for n in range(n_child):
  274.             HideObject(obj.GetChild(n))
  275.             
  276.             
  277. def HideBadGuy(name,ciego=1,sordo=1):
  278.     pers = Bladex.GetEntity(name)
  279.     if not pers:
  280.         print "WARNING : Trying to hide `"+name+"`but was deleted !"
  281.         return
  282.     pers.Deaf  = sordo
  283.     pers.Blind = ciego
  284.     pers.Freeze()
  285.     pers.RemoveFromWorld()
  286.     HideObject(pers.InvLeft)
  287.     HideObject(pers.InvRight)
  288.     HideObject(pers.InvRightBack)
  289.     HideObject(pers.InvLeftBack)
  290.     HideObject(pers.InvLeft2)
  291.     char = Bladex.GetEntity("Player1")
  292.     if char.ActiveEnemy == name:
  293.         char.SetActiveEnemy("")
  294.         
  295.  
  296. def UnhideBadGuy(name):
  297.     pers = Bladex.GetEntity(name)
  298.     pers.Deaf  = 0
  299.     pers.Blind = 0
  300.     pers.UnFreeze()
  301.     pers.PutToWorld()
  302.     UnhideObject(pers.InvLeft)
  303.     UnhideObject(pers.InvRight)
  304.     UnhideObject(pers.InvRightBack)
  305.     UnhideObject(pers.InvLeftBack)
  306.     UnhideObject(pers.InvLeft2)
  307.  
  308.  
  309. ############ Hint Funcs ############
  310. def OnUse(entity, onuse ):
  311.   import GameText
  312.   GameText.WriteText(Bladex.GetEntity(entity).Data.MessageHint)
  313.  
  314. class EmptyClass:
  315.     pass
  316.  
  317.  
  318. def SetHint(gp,Name,OnUseData="",Priority=8.0,Distance=4000.0):
  319.     Reference.EntitiesSelectionData[gp.Name]=(Priority,Distance,Name)
  320.     
  321.     if type(OnUseData)==type(""):
  322.         if OnUseData != "":
  323.             gp.UseFunc          = OnUse
  324.             if not gp.Data:
  325.                 gp.Data = EmptyClass()
  326.             gp.Data.MessageHint = OnUseData
  327.     else:
  328.         gp.UseFunc = OnUseData
  329.  
  330. # SetHint(Bladex.GetEntity(char.InvRight),"Mierda","M7T4")
  331.  
  332. ############ Quake steps funcs (no rocketlauncher avail) ############
  333. QuakeFactor = 100
  334.  
  335. def QuakeStep(personaje):
  336.     global QuakeFactor
  337.     
  338.     cam = Bladex.GetEntity("Camera")
  339.     cam.EarthQuakeFactor = QuakeFactor
  340.     cam.EarthQuake = 1
  341.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.125, QuakeHalf,())
  342.  
  343. def QuakeHalf():
  344.     QuakeStepCounter = 1
  345.     cam = Bladex.GetEntity("Camera")
  346.     cam.EarthQuakeFactor = cam.EarthQuakeFactor/2
  347.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.125, QuakeStop,())
  348.  
  349. def QuakeStop():
  350.     QuakeStepCounter = 2
  351.     cam = Bladex.GetEntity("Camera")
  352.     cam.EarthQuakeFactor = 0
  353.     cam.EarthQuake = 0
  354.  
  355. ######## FIRE SECTORS #######
  356. FIRE_DAMAGE = 1
  357.  
  358. def QuemaTimer(e_name, time):
  359.   char = Bladex.GetEntity(e_name)
  360.   char.Life = char.Life - FIRE_DAMAGE
  361.   if char.Life <= 0:
  362.     Actions.FireDeath(e_name)
  363.     char.RemoveFromList("Timer15")
  364.     char.TimerFunc=""
  365.  
  366. def EntraQuema(triggername,entityname):
  367.   if entityname=="Player1":
  368.     char = Bladex.GetEntity("Player1")
  369.     char.SubscribeToList("Timer15")
  370.     char.TimerFunc=QuemaTimer
  371.  
  372. def SaleQuema(triggername,entityname):
  373.   if entityname=="Player1":
  374.     char = Bladex.GetEntity("Player1")
  375.     char.RemoveFromList("Timer15")
  376.     char.TimerFunc=""
  377.  
  378. ######  Assignation funcs ######
  379. def FireOnGS(name):
  380.     Bladex.SetTriggerSectorFunc(name, "OnEnter", EntraQuema )
  381.     Bladex.SetTriggerSectorFunc(name, "OnLeave", SaleQuema  )
  382.  
  383. def FireOnS(sec):
  384.         sec.OnEnter = EntraQuema
  385.         sec.OnLeave = SaleQuema
  386.  
  387. ######## NAILS DAMAGE ########
  388.  
  389. def EntraPincha(triggername,entityname):
  390.     import Scorer
  391.     ent = Bladex.GetEntity ( entityname )
  392.     if (ent.Person):
  393.         if entityname=="Player1":
  394.             Bladex.GetEntity("Camera").TType=0
  395.             AuxFuncs.FadeTo(1.0,60.0,32,0,0)
  396.             Scorer.SetVisible(0)
  397.         Bladex.AddScheduledFunc(Bladex.GetTime()+0.5, MuereDeVerdadPincha,(ent,))
  398.  
  399.         p = ent.Position
  400.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],9999,0,0 )
  401.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],9999,0,9999 )
  402.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],3333,0,0 )
  403.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],9999,0,3333 )
  404.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],0,0,3333 )
  405.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],0,0,9999 )
  406.         #Blood.BleedingImpact(ent , p[0], p[1], p[2],0,0,0 )
  407.  
  408. def MuereDeVerdadPincha(ent):        
  409.         ent.Life = 0
  410.         ent.Wuea = Reference.WUEA_ENDED
  411.         ent.SetTmpAnmFlags(1,1,1,0,5,1,0)
  412.         ent.LaunchAnmType("dth_rock")        
  413.         
  414. def NailOnGS(name):
  415.         Bladex.SetTriggerSectorFunc(name, "OnEnter", EntraPincha )
  416.  
  417. def NailOnS(sec):
  418.         sec.OnEnter = EntraPincha
  419.  
  420. ######## Enemy Deaths Detector #######
  421. class E_Grup:
  422.  
  423.     ObjId=0
  424.     n=0
  425.     OnDeath=None
  426.     Guys = []
  427.     ImDeadFuncs = {}
  428.     
  429.     def __init__(self):
  430.         self.ObjId=ObjStore.GetNewId() # Para identificarlo al grabar/guardar        
  431.         self.n           = 0    # Zero enemies
  432.         self.OnDeath     = None # No Callback
  433.         self.Guys        = []
  434.         self.ImDeadFuncs = {}
  435.         ObjStore.ObjectsStore[self.ObjId]=self
  436.  
  437.     def __del__(self):
  438.         del ObjStore.ObjectsStore[self.ObjId]
  439.  
  440.     def persistent_id(self):
  441.         return self.ObjId
  442.  
  443.     def ImDeadFunc(self,Name):
  444.         self.ImDeadFuncs[Name](Name)
  445.         self.n = self.n - 1
  446.         print "Quedan",self.n
  447.         self.Guys.remove(Name)
  448.         if self.n == 0:
  449.             if self.OnDeath:
  450.                 self.OnDeath()
  451.             
  452.     def AddGuy(self,Name):
  453.         e                      = Bladex.GetEntity(Name)        
  454.         self.ImDeadFuncs[Name] = e.ImDeadFunc
  455.         e.ImDeadFunc           = self.ImDeadFunc
  456.         self.n = self.n + 1
  457.         if Name in self.Guys:
  458.             print "E_Grup error : "+Name+" is allready here."
  459.         else:
  460.             self.Guys.append(Name)
  461.     
  462.     def HideBadGuys(self):
  463.         for Name in self.Guys:
  464.             HideBadGuy(Name)
  465.     
  466.     def UnhideBadGuys(self,number):
  467.         counter = 0
  468.         for Name in self.Guys:
  469.             counter = counter+1
  470.             UnhideBadGuy(Name)
  471.             if counter>=number:
  472.                 return counter
  473.         return counter
  474.     
  475.     def __getstate__(self):
  476.         # Tiene que devolver cΣ«» poder guardar el estado de la clase
  477.         return (1,
  478.                     self.ObjId, # De GameStateAux.PersistentObject
  479.                     self.n,
  480.                     GameStateAux.SaveFunctionAux(self.OnDeath),
  481.                     self.Guys,
  482.                     self.ImDeadFuncs
  483.                 )
  484.  
  485.  
  486.     def __setstate__(self,parm):
  487.         # Toma como parΓ«Ñtro lo que devuelve __getstate__() y debe recrear la clase
  488.         if parm[0]==1:
  489.             #self.ObjId=parm[1] En GameStateAux.PersistentObject()
  490. ##            GameStateAux.PersistentObject.__setstate__(self,parm)
  491.             self.ObjId=parm[1]
  492.             ObjStore.ObjectsStore[self.ObjId]=self
  493.             self.n=parm[2]
  494.             GameStateAux.LoadFunctionAux(parm[3],self,"OnDeath")
  495.             self.Guys=parm[4]
  496.             self.ImDeadFuncs=parm[5]
  497.  
  498.  
  499.         else:
  500.             print "Door.__setstate__() -> Version mismatch"
  501.             # Valores por si valen para algo.
  502.             self.ObjId=ObjStore.GetNewId()
  503.             ObjStore.ObjectsStore[self.ObjId]=self    
  504.  
  505. #----------------------------------------------------------------#
  506.  
  507. PersonasEnLlamas = []
  508.  
  509. def EnciendeEnLlamas(o,Intensity = 15,Precission=0.1):
  510.     global PersonasEnLlamas
  511.     
  512.     if not (o.Kind in PersonasEnLlamas):
  513.         PersonasEnLlamas.append(o.Kind)
  514.         Bladex.AddCombustionDataFor(o.Kind, "Fire", 250, 400, 4, 1, 3, 144000) # se extingira en 40 horas!
  515.     
  516.     o.SelfIlum = 0.0
  517.     o.CatchOnFire(0,0,0)
  518.     
  519.     luz             = Bladex.CreateEntity(o.Name+"Luz","Entity Spot",0,0,0)
  520.     luz.Color       = 200,100,0
  521.     luz.Intensity   = Intensity
  522.     luz.Precission  = Precission
  523.     luz.CastShadows = 0
  524.     luz.Visible     = 1
  525.     luz.SizeFactor  = 0
  526.  
  527.     o.Link(luz)
  528.  
  529. ### objetos Alfa ###
  530. def ObjAlpha(o,alpha=0.8,SelfIlum=0.0):
  531.     o.Alpha       = alpha
  532.     o.RasterMode  ="AdditiveAlpha"
  533.     o.RasterMode  ="Read"
  534.     o.CastShadows = 0
  535.     o.SelfIlum    = SelfIlum
  536.     
  537.     
  538.     
  539. #----------------------------------------------------------------#
  540. #  Funciones auxiliares para la aparicion valida de objetos      #
  541. #----------------------------------------------------------------#    
  542.  
  543. def ValidAppear(pos,func=None,param=None):
  544.     entid = Bladex.GetEntitiesAt(pos[0],pos[1],pos[2],4000)
  545.     for on in entid:
  546.         o = Bladex.GetEntity(on)
  547.         if o.Person:
  548.             if o.Life > 0:
  549.                 if o.Alpha >0.01:
  550.                     print "Trying to do it, but",on,"is bothering. Next try in 5 seconds."
  551.                     if func:
  552.                         Bladex.AddScheduledFunc(Bladex.GetTime()+5.0, ValidAppear,(pos,func,param))
  553.                     return 0
  554.     if func:
  555.         apply(func,param)
  556.         print "The function was XQted"
  557.     else:
  558.         return 1
  559.  
  560. def CreateFalseCube(pos,timeToKill = -1,Name = ""):
  561.     o = Bladex.CreateEntity(Name + "quad","Bloque",pos[0],pos[1]-1500,pos[2])
  562.     o.Orientation = (0.707107245922, 0.0, 0.0, 0.707106292248)
  563.     o.Scale = 4
  564.     o.CastShadows = 0
  565.     o.Alpha       = 0.0
  566.     o.RasterMode  ="Read"
  567.     if timeToKill != -1:
  568.         Bladex.AddScheduledFunc(Bladex.GetTime()+timeToKill, o.SubscribeToList,("Pin",))
  569.     return o
  570.     
  571.     
  572. #
  573. #  Destroy the pools and cadavres but the limbs and weapons, no.
  574. #----------------------------------------------------------------#    
  575. def CleanArea(x,y,z,radius):
  576.     list = Bladex.GetEntitiesAt(x,y,z,radius)
  577.     enCounter = 0
  578.     
  579.     for name in list:
  580.         o = Bladex.GetEntity(name)
  581.         if o.Kind == "Entity Pool":
  582.             o.SubscribeToList("Pin")
  583.         if o.Person:
  584.             if o.Life <= 0.0:
  585.                 if o.Name != "Player1":
  586.                     HideBadGuy(o.Name)
  587.                     enCounter = enCounter + 1
  588.     
  589.     return enCounter
  590.  
  591. #
  592. # Detects if a player joins into a sector
  593. #--------------------------------------------#
  594. def EnterSecEvent(x,y,z,func):    
  595.     sec = Bladex.GetSector(x,y,z)
  596.     EnterSecEventSector(sec,func)
  597.  
  598. def GetSectorIdx(pos):
  599.     if (type(pos)!=types.TupleType):
  600.         return pos
  601.     else:
  602.         return Bladex.GetSector(pos[0],pos[1],pos[2]).Index
  603.         
  604. def EnterSecIdEvent(id,func):
  605.     if type(id)==types.StringType:
  606.         EnterTSEvent(id,func)
  607.         return id
  608.     elif type(id)==types.TupleType:
  609.         sec = Bladex.GetSector(id[0],id[1],id[2])
  610.         EnterSecEventSector(sec,func)
  611.         return sec.Index
  612.     else:
  613.         sec = Bladex.GetSector(id)
  614.         EnterSecEventSector(sec,func)
  615.         return id
  616.  
  617. def EnterSecEventSector(sec,func):
  618.     global SectorTable
  619.  
  620.     if sec:
  621.         if not SectorTable.has_key(sec.Index):
  622.             if sec.OnEnter:
  623.                 print "ERROR : OnEnter Asigned to",sec.OnEnter
  624.             else:
  625.                 SectorTable[sec.Index]=[]
  626.         else:
  627.             numerox = len(SectorTable[sec.Index])
  628.             if numerox>0:
  629.                 if Reference.PYTHON_DEBUG >= 2:
  630.                     print "Warning : OnEnter have",numerox,"functions"
  631.             
  632.         SectorTable[sec.Index].insert(0,func)
  633.         sec.OnEnter = OnPlayerEnter
  634.         return sec.Index
  635.     else:
  636.         print "ERROR : Sector invalid!"
  637.     
  638. def OnPlayerEnter(sectorindex,entityname):
  639.     global SectorTable
  640.     
  641.     if entityname == "Player1":
  642.         funclist = []
  643.         
  644.         # guarda la lista de funciones a ejecutar
  645.         for f in SectorTable[sectorindex]:
  646.             funclist.append(f)
  647.         
  648.         # borra la lista y todo lo relacionado a ella
  649.         del SectorTable[sectorindex]
  650.         if type(sectorindex)==types.StringType:
  651.             Bladex.SetTriggerSectorFunc(sectorindex, "OnEnter", None )
  652.         else:
  653.             Bladex.GetSector(sectorindex).OnEnter = None
  654.         
  655.         # elimina las funciones que se llaman si se entra en mas de un sector
  656.         for f in funclist:
  657.             for key in SectorTable.keys():
  658.                 for e in SectorTable[key]:
  659.                     if e == f:
  660.                         SectorTable[key].remove(e)
  661.         
  662.         # ejecuta la lista de funciones en cuestion
  663.         for f in funclist:            
  664.             try:
  665.                 f()
  666.             except:
  667.                 f(sectorindex)
  668.     
  669.     
  670. SectorTable = {}
  671.  
  672. #
  673. ##   Ghost sector tools
  674. ####################################
  675. def EnterTSEvent(secname,func):
  676.     global SectorTable
  677.  
  678.     if secname:
  679.         if not SectorTable.has_key(secname):
  680.             if Bladex.GetTriggerSectorFunc(secname,"OnEnter"):
  681.                 print "ERROR : OnEnter Asigned to ",secname
  682.             else:
  683.                 SectorTable[secname]=[]
  684.         else:
  685.             numerox = len(SectorTable[secname])
  686.             if numerox>0:
  687.                 if Reference.PYTHON_DEBUG >= 2:
  688.                     print "Warning : OnEnter have",numerox,"functions"            
  689.         SectorTable[secname].insert(0,func)
  690.         Bladex.SetTriggerSectorFunc(secname, "OnEnter", OnPlayerEnter )        
  691.         return secname
  692.     else:
  693.         print "ERROR : Sector '"+secname+"' invalid!"
  694.  
  695. # darfuncs.EnterSecEvent(char.Position[0],char.Position[1],char.Position[2],x)
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702. ###
  703. ###  Template to make a clean in a area.
  704. ###
  705. ##import darfuncs
  706. ##
  707. ##def EntrayBorra():
  708. ##    darfuncs.CleanArea(clnX,clnY,clnZ,clnRadius)
  709. ##    
  710. ##darfuncs.EnterSecEvent(secX,secY,secZ,EntrayBorra)
  711.  
  712.  
  713.  
  714. def LuzChapuzera(light,FinishTime,delta = 1):
  715.     t = Bladex.GetTime()    
  716.     light.Move(0,0,delta)
  717.     if t<FinishTime:
  718.         Bladex.AddScheduledFunc(t+0.0, LuzChapuzera,(light,FinishTime,-delta))
  719.  
  720. ###
  721. ### Chapuza solution with the light cones
  722. ###
  723. ##
  724. ##darfuncs.LuzChapuzera(Bladex.GetEntity("luzbonita"), Bladex.GetTime() + 3.0) # mueve "luzbonita" durante 3 segundos
  725.  
  726.  
  727. def SaveData(filename):
  728.   import cPickle
  729.  
  730.   funcfile=open(filename,"wt")
  731.   p=cPickle.Pickler(funcfile)
  732.   d=(muertonum,ActualLevel,QuakeFactor,FIRE_DAMAGE,PersonasEnLlamas,SectorTable)
  733.   p.dump(d)
  734.   funcfile.close()
  735.  
  736.  
  737. def LoadData(filename):
  738.   import cPickle
  739.  
  740.   funcfile=open(filename,"rt")
  741.   p=cPickle.Unpickler(funcfile)
  742.   d=p.load()
  743.   funcfile.close()
  744.   print d
  745.  
  746.   global muertonum
  747.   global ActualLevel
  748.   global QuakeFactor
  749.   global FIRE_DAMAGE
  750.   global PersonasEnLlamas
  751.   global SectorTable
  752.   
  753.   muertonum=d[0]
  754.   ActualLevel=d[1]
  755.   QuakeFactor=d[2]
  756.   FIRE_DAMAGE=d[3]
  757.   PersonasEnLlamas=d[4]
  758.   SectorTable=d[5]
  759.  
  760.  
  761.  
  762. import GameState
  763. GameState.ModulesToBeSaved.append(__import__(__name__))
  764.