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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import math
  5. import Bladex
  6. import Sounds
  7. import GameStateAux
  8. import ObjStore
  9. stoneDrop = '..\\..\\Sounds\\golpe-bola-piedra.wav'
  10. stoneLoop = '..\\..\\Sounds\\piedra-rodando-1.wav'
  11. stoneDSound = Sounds.CreateEntitySound(stoneDrop, 'stoneSound')
  12. stoneDSound.Volume = 1.0
  13. stoneDSound.MinDistance = 10000
  14. stoneDSound.MaxDistance = 90000
  15. MESSAGE_START_WEAPON = 7
  16. MESSAGE_STOP_WEAPON = 8
  17. SQR_DELTA_HIT_VARIATION = 10000000
  18.  
  19. class DataStone:
  20.     ObjId = ''
  21.     stoneDictionary = None
  22.     stoneDictionaryB = None
  23.     stoneDictionaryC = None
  24.     stoneDictionaryD = None
  25.     Entidad = None
  26.     LastDelta = (0, 0, 0)
  27.     
  28.     def __init__(self, entName, A, B, C, D):
  29.         self.ObjId = ObjStore.GetNewId()
  30.         self.stoneDictionary = A
  31.         self.stoneDictionaryB = B
  32.         self.stoneDictionaryC = C
  33.         self.stoneDictionaryD = D
  34.         self.Entidad = entName
  35.         ObjStore.ObjectsStore[self.ObjId] = self
  36.         self.LastDelta = (0, 0, 0)
  37.  
  38.     
  39.     def __del__(self):
  40.         del ObjStore.ObjectsStore[self.ObjId]
  41.  
  42.     
  43.     def persistent_id(self):
  44.         return self.ObjId
  45.  
  46.     
  47.     def __getstate__(self):
  48.         return (1, self.ObjId, self.stoneDictionary, self.stoneDictionaryB, GameStateAux.SaveEntityAux(self.stoneDictionaryC), GameStateAux.SaveEntityAux(self.stoneDictionaryD), self.Entidad, GameStateAux.SaveNewMembers(self))
  49.  
  50.     
  51.     def __setstate__(self, parm):
  52.         if parm[0] == 1:
  53.             self.ObjId = parm[1]
  54.             ObjStore.ObjectsStore[self.ObjId] = self
  55.             self.stoneDictionary = parm[2]
  56.             self.stoneDictionaryB = parm[3]
  57.             self.stoneDictionaryC = GameStateAux.LoadEntityAux(parm[4])
  58.             self.stoneDictionaryD = GameStateAux.LoadEntityAux(parm[5])
  59.             self.Entidad = GameStateAux.LoadEntityAux(parm[6])
  60.             self.Entidad.Data = self
  61.             self.Entidad = parm[6]
  62.             GameStateAux.LoadNewMembers(self, parm[7])
  63.             self.LastDelta = (0, 0, 0)
  64.         else:
  65.             self.stoneDictionary = (0, 0, 0, 0, 0, 0, 0, 0, 0)
  66.             self.stoneDictionaryB = (0, 0, 0)
  67.             self.stoneDictionaryC = None
  68.             self.stoneDictionaryD = None
  69.             self.Entidad = None
  70.             self.ObjId = ObjStore.GetNewId()
  71.             ObjStore.ObjectsStore[self.ObjId] = self
  72.             self.LastDelta = (0, 0, 0)
  73.  
  74.  
  75. Bladex.CreateTimer('stoneLibTimer', 0.1)
  76. B_PARTICLE_GTYPE_BLEND = 1
  77. Bladex.AddParticleGType('DesertDustB', 'SmokeParticle', B_PARTICLE_GTYPE_BLEND, 32)
  78. for i in range(32):
  79.     r = 200
  80.     g = 170
  81.     b = 140
  82.     a = i + 50.0
  83.     size = (i / 32.0) * 1000.0
  84.     Bladex.SetParticleGVal('DesertDustB', i, r, g, b, a, size)
  85.  
  86. Bladex.AddParticleGType('DesertDarkDustB', 'SmokeParticle', B_PARTICLE_GTYPE_BLEND, 32)
  87. for i in range(32):
  88.     r = 85
  89.     g = 55
  90.     b = 35
  91.     a = i + 125.0
  92.     size = (i / 32.0) * 1500.0
  93.     Bladex.SetParticleGVal('DesertDarkDustB', i, r, g, b, a, size)
  94.  
  95. DROPNULL = 0
  96. DROPBROWNDUST = 1
  97. DROPDARKDUST = 2
  98. SOUNDNULL = 0
  99. STONESOUND = 1
  100.  
  101. def cuadradox(x):
  102.     return x * x
  103.  
  104.  
  105. def stoneHandler(ent, time):
  106.     sto = Bladex.GetEntity(ent)
  107.     stoneData = sto.Data
  108.     params = stoneData.stoneDictionary
  109.     pos = sto.Position
  110.     cpos = (pos[0] + params[1], pos[1] + params[2], pos[2] + params[3])
  111.     ppos = stoneData.stoneDictionaryB
  112.     stoneData.stoneDictionaryB = cpos
  113.     dx = ppos[0] - cpos[0]
  114.     dy = ppos[1] - cpos[1]
  115.     dz = ppos[2] - cpos[2]
  116.     size = math.sqrt(dx * dx + dy * dy + dz * dz)
  117.     eval = size * stoneData.stoneDictionary[5]
  118.     deltaVariation = cuadradox(dx - stoneData.LastDelta[0]) + cuadradox(dx - stoneData.LastDelta[1]) + cuadradox(dx - stoneData.LastDelta[2])
  119.     if SQR_DELTA_HIT_VARIATION < deltaVariation:
  120.         stoneDSound.Position = pos
  121.         if not (stoneDSound.Playing):
  122.             stoneDSound.PlaySound(0)
  123.         
  124.     
  125.     dtype = stoneData.stoneDictionary[0]
  126.     if dtype != DROPNULL and stoneData.stoneDictionaryC:
  127.         if dtype == DROPBROWNDUST:
  128.             dust = stoneData.stoneDictionaryC
  129.             dust.Position = cpos
  130.             dust.D1 = (dx, dy, dz)
  131.             dust.PPS = eval
  132.         elif dtype == DROPDARKDUST:
  133.             dust = stoneData.stoneDictionaryC
  134.             dust.Position = cpos
  135.             dust.D1 = (dx, dy, dz)
  136.             dust.PPS = eval * 0.85
  137.         
  138.     
  139.     stype = params[6]
  140.     if stype != SOUNDNULL and stoneData.stoneDictionaryD:
  141.         if stype == STONESOUND:
  142.             sound = stoneData.stoneDictionaryD
  143.             soundvolume = eval * 0.025 * params[7]
  144.             sound.Position = cpos
  145.             if soundvolume > 1.0:
  146.                 soundvolume = 1.0
  147.             
  148.             sound.Volume = 1
  149.             if not (sound.Playing):
  150.                 sound.PlaySound(0)
  151.             
  152.         
  153.     
  154.     stoneData.LastDelta = (dx, dy, dz)
  155.  
  156.  
  157. def lock(entName, trail, offsetX, offsetY, offsetZ, trailParam, autodest, sound, soundParam):
  158.     ent = Bladex.GetEntity(entName)
  159.     stoneDictionary = (trail, offsetX, offsetY, offsetZ, autodest, trailParam, sound, soundParam)
  160.     stoneDictionaryB = (ent.Position[0] + offsetX, ent.Position[1] + offsetY, ent.Position[2] + offsetZ)
  161.     stoneDictionaryC = 0
  162.     stoneDictionaryD = 0
  163.     if trail != DROPNULL:
  164.         if trail == DROPBROWNDUST:
  165.             stoneDust = Bladex.CreateEntity('ps' + entName, 'Entity Particle System D2', ent.Position[0], ent.Position[1], ent.Position[2])
  166.             stoneDust.D1 = (0, 0, 0)
  167.             stoneDust.ParticleType = 'DesertDustB'
  168.             stoneDust.YGravity = -1030.0
  169.             stoneDust.Friction = 0.3
  170.             stoneDust.PPS = 0
  171.             stoneDust.DeathTime = Bladex.GetTime() + 999999.0
  172.             stoneDust.Time2Live = 31
  173.             stoneDust.Velocity = (0.0, 4000.0, 0.0)
  174.             stoneDust.RandomVelocity = 110.0
  175.             stoneDictionaryC = stoneDust
  176.         elif trail == DROPDARKDUST:
  177.             stoneDust = Bladex.CreateEntity('ps' + entName, 'Entity Particle System D2', ent.Position[0], ent.Position[1], ent.Position[2])
  178.             stoneDust.D1 = (0, 0, 0)
  179.             stoneDust.ParticleType = 'DesertDarkDustB'
  180.             stoneDust.YGravity = -1030.0
  181.             stoneDust.Friction = 0.3
  182.             stoneDust.PPS = 0
  183.             stoneDust.DeathTime = Bladex.GetTime() + 999999.0
  184.             stoneDust.Time2Live = 31
  185.             stoneDust.Velocity = (0.0, 4000.0, 0.0)
  186.             stoneDust.RandomVelocity = 110.0
  187.             stoneDictionaryC = stoneDust
  188.         
  189.     
  190.     if sound != SOUNDNULL:
  191.         if sound == STONESOUND:
  192.             stonelSound = Sounds.CreateEntitySound(stoneLoop, 'stoneSound')
  193.             stonelSound.Volume = 1
  194.             stonelSound.MinDistance = 7000
  195.             stonelSound.MaxDistance = 70000
  196.             stoneDictionaryD = stonelSound
  197.         
  198.     
  199.     ent.Data = DataStone(entName, stoneDictionary, stoneDictionaryB, stoneDictionaryC, stoneDictionaryD)
  200.  
  201.  
  202. def unlock(entName):
  203.     ent = Bladex.GetEntity(entName)
  204.     ent.TimerFunc = ''
  205.     ent.RemoveFromList('stoneLibTimer')
  206.     stoneData = ent.Data
  207.     if stoneData.stoneDictionary[0] != DROPNULL and stoneData.stoneDictionaryC:
  208.         stoneData.stoneDictionaryC.DeathTime = Bladex.GetTime()
  209.     
  210.     if stoneData.stoneDictionary[6] != SOUNDNULL and stoneData.stoneDictionaryD:
  211.         stoneData.stoneDictionaryD.StopSound()
  212.     
  213.     del stoneData
  214.  
  215.  
  216. def drop(entName, impulseX, impulseY, impulseZ):
  217.     ent = Bladex.GetEntity(entName)
  218.     ent.Impulse(impulseX, impulseY, impulseZ)
  219.     ent.TimerFunc = stoneHandler
  220.     ent.SubscribeToList('stoneLibTimer')
  221.     ent.MessageEvent(MESSAGE_START_WEAPON, 0, 0)
  222.     autodest = ent.Data.stoneDictionary[4]
  223.     if autodest > 0.0:
  224.         import stone
  225.         Bladex.AddScheduledFunc(Bladex.GetTime() + ent.Data.stoneDictionary[4], stone.unlock, (entName,))
  226.     
  227.     if ent.Data.stoneDictionary[6] != SOUNDNULL and ent.Data.stoneDictionaryD:
  228.         snd = ent.Data.stoneDictionaryD
  229.         stoneDSound.Position = ent.Position
  230.         stoneDSound.PlaySound(0)
  231.     
  232.  
  233.