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

  1. import Bladex
  2. import InitDataField
  3. import AuxFuncs
  4. import Actions
  5.  
  6.  
  7. OFF=0
  8. ON=1
  9. DEAD=0
  10. ALIVE=1
  11.  
  12.  
  13. tipos_antorcha=("Antorcha", "Antorchaenpared", "Palangana")
  14.  
  15.  
  16. class TorchObj:
  17.  
  18.     pass
  19.  
  20.  
  21. def ExtingueGradual(torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int, OnEndExtinctionFunc, OnEndExtinctionArgs):
  22.     if torchspot.Intensity>0.0:
  23.         torchspot.Intensity=torchspot.Intensity-intensity_var
  24.     else:
  25.         torchspot.Intensity = 0
  26.     fire_int=fire_int+fire_var
  27.     torchfire.Intensity=fire_int
  28.     if torchfire.Intensity>=30.0:
  29. #        print "Apagada..."
  30.         torchobj.LiveStatus=DEAD
  31.         torchobj.LightStatus=OFF
  32.         if OnEndExtinctionFunc:
  33.             apply(OnEndExtinctionFunc, OnEndExtinctionArgs)
  34.         return
  35.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, ExtingueGradual, (torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int, OnEndExtinctionFunc, OnEndExtinctionArgs))
  36.  
  37.  
  38. def ExtingueAntorcha(torch_name, OnEndExtinctionFunc="", OnEndExtinctionArgs=()):
  39.     torch=Bladex.GetEntity(torch_name)
  40.     torchspot=AuxFuncs.GetSpot(torch)
  41.     torchfire=AuxFuncs.GetFire(torch)
  42.     torchobj=torch.Data.torchobjdata
  43.     if torchspot.Intensity<=0.0:
  44. #        print "Ya esta apagada..."
  45.         return
  46.     intensity_var=torchspot.Intensity/20.0
  47.     fire_var=(30.0-torchfire.Intensity)/60.0
  48.     fire_int=torchfire.Intensity
  49.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, ExtingueGradual, (torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int, OnEndExtinctionFunc, OnEndExtinctionArgs))
  50.  
  51.  
  52. def EnciendeGradual(torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int):
  53.     torchspot.Intensity=torchspot.Intensity+intensity_var
  54.     fire_int=fire_int-fire_var
  55.     torchfire.Intensity=fire_int
  56.     if torchspot.Intensity>=torchobj.LightIntensity:
  57. #        print "Encendida..."
  58.         torchobj.LightStatus=ON
  59.         return
  60.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, EnciendeGradual, (torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int))
  61.  
  62.  
  63. def EnciendeAntorcha(torch_name):
  64.     torch=Bladex.GetEntity(torch_name)
  65.     torchspot=AuxFuncs.GetSpot(torch)
  66.     torchfire=AuxFuncs.GetFire(torch)
  67.     torchobj=torch.Data.torchobjdata
  68.     if torchobj.LightStatus==ON:
  69. #        print "Ya esta encendida..."
  70.         return
  71.     intensity_var=torchobj.LightIntensity/20.0
  72.     fire_var=(10.0-torchobj.FireIntensity)/20.0
  73.     torchfire.Intensity=10.0
  74.     fire_int=torchfire.Intensity
  75.     Bladex.AddScheduledFunc(Bladex.GetTime()+0.1, EnciendeGradual, (torchobj, torchspot, torchfire, intensity_var, fire_var, fire_int))
  76.  
  77.  
  78. def EnciendeEstaAntorcha(person_name, event_name):
  79.     pj=Bladex.GetEntity(person_name)
  80.     pj.DelAnmEventFunc(event_name)
  81.     torch=pj.Data.obj_used
  82.     torchobj=torch.Data.torchobjdata
  83.     objright=Bladex.GetEntity(pj.InvRight)
  84.     objrighttorch=objright.Data.torchobjdata
  85.     if objrighttorch.LightStatus==OFF and torchobj.LightStatus==ON:
  86. #        print "Enciendo mi antorcha..."
  87.         EnciendeAntorcha(objright.Name)
  88.         if objrighttorch.Life>0.0:
  89.             Bladex.AddScheduledFunc(Bladex.GetTime()+objrighttorch.Life, ExtingueAntorcha, (objright.Name,))
  90.     else:
  91. #        print "Enciendo la antorcha de la pared..."
  92.         EnciendeAntorcha(torch.Name)
  93.         if torchobj.Life>0.0:
  94.             Bladex.AddScheduledFunc(Bladex.GetTime()+torchobj.Life, ExtingueAntorcha, (torch.Name,))
  95.  
  96.  
  97. def TorchUseFunc(torch_name, use_from):
  98.     global UseFunc
  99.     
  100.     torch=Bladex.GetEntity(torch_name)    
  101.     pj=Bladex.GetEntity("Player1")
  102.     objright=Bladex.GetEntity(pj.InvRight)
  103.     if objright and (torch.Kind in tipos_antorcha) and (objright.Kind in tipos_antorcha):
  104.         torchobj=torch.Data.torchobjdata
  105.         objrighttorch=objright.Data.torchobjdata
  106.         if (objrighttorch.LightStatus==OFF and torchobj.LightStatus==OFF) or (objrighttorch.LightStatus==ON and torchobj.LightStatus==ON):
  107. #            print "No puedo encender. Ambas antorchas estan encendidas o apagadas..."
  108.             return
  109.         if (torchobj.LiveStatus==DEAD) or (objrighttorch.LiveStatus==DEAD):
  110. #            print "Esta antorcha esta extinta..."
  111.             return
  112.         Actions.QuickTurnToFaceEntity("Player1", torch_name)
  113.         difalt=-(torch.Position[1]-(pj.Position[1]+pj.Dist2Floor))
  114.         chartype=Bladex.GetCharType(pj.CharType, pj.CharTypeExt)
  115.         if difalt<=chartype.MaxTake1:
  116.             pj.LaunchAnmType("fire_g")
  117.         elif difalt<=chartype.MaxTake2:
  118.             pj.LaunchAnmType("fire0")
  119.         elif difalt<=chartype.MaxTake3:
  120.             pj.LaunchAnmType("fire1")
  121.         elif difalt<=chartype.MaxTake4:
  122.             pj.LaunchAnmType("fire2")
  123.         elif difalt<=chartype.MaxTake5:
  124.             pj.LaunchAnmType("fire3")
  125.         else:
  126. #            print "Demasiado alta..."
  127.             return
  128.         if UseFunc:
  129.             UseFunc(torch.Name, objright.Name)
  130.         pj.AddAnmEventFunc("SetAlightEvent", EnciendeEstaAntorcha)
  131. #    else:
  132. #        print "No tengo antorcha..."
  133.  
  134.  
  135. def SetUsable(obj_name, light_int=3.0, fire_int=3.0, life=-1):
  136.     obj=Bladex.GetEntity(obj_name)
  137.     if obj.Kind not in tipos_antorcha:
  138. #        print "El objeto "+obj_name+" no es una antorcha o no esta definido como tal en tipos_antorcha"
  139.         return
  140.     torchobj=TorchObj()
  141.     torchobj.LightIntensity=light_int
  142.     torchobj.FireIntensity=fire_int
  143.     torchobj.Life=life
  144.     if AuxFuncs.GetSpot(obj).Intensity==0.0:
  145.         torchobj.LightStatus=OFF
  146.     else:
  147.         torchobj.LightStatus=ON
  148.     if life==0:
  149.         torchobj.LiveStatus=DEAD
  150.     else:
  151.         torchobj.LiveStatus=ALIVE
  152.     InitDataField.Initialise(obj)
  153.     obj.Data.torchobjdata=torchobj
  154.     if obj.Kind!="Antorcha":    # This type is carryable
  155.         obj.UseFunc=TorchUseFunc    
  156.  
  157.  
  158. UseFunc = None         # UseFunc(from,to)