###############################################################################
#	Filename:	Mark9Tactical.py
#	
#	Confidential and Proprietary, Copyright 2000 by Totally Games
#	
#	Script for filling in the attributes of photon torpedoes.
#	
#	Modified:       29/10/2006 -    Lost_Jedi
#                                           Now includes torpedo trails
###############################################################################

import App
import LJTorpLib.LibTorp

sDamage = 1800 #### R.A Change this value to the value you want the max standard damage to be

###############################################################################
#	Create(pTorp)
#	
#	Creates a photon torpedo.
#	
#	Args:	pTorp - the torpedo, ready to be filled-in
#	
#	Return:	zero
###############################################################################
def Create(pTorp):
	kCoreColor = App.TGColorA()
	kCoreColor.SetRGBA(255.0 / 255.0, 255.0 / 255.0, 128.0 / 255.0, 1.000000)
	kGlowColor = App.TGColorA()
	kGlowColor.SetRGBA(255.0 / 255.0, 128.0 / 255.0, 0.0 / 255.0, 1.000000)
	kFlareColor = App.TGColorA()
	kFlareColor.SetRGBA(255.0 / 255.0, 128.0 / 255.0, 0.0 / 255.0, 1.000000)		

	pTorp.CreateTorpedoModel(
					"data/Textures/Tactical/TorpedoCore.tga",
					kCoreColor,
					0.04,
					0.05,	 
					"data/Textures/Tactical/TorpedoGlow.tga", 
					kGlowColor,
					0.2,	
					0.04,	 
					0.025,	
					"data/Textures/Tactical/TorpedoFlares.tga",
					kFlareColor,										
					0,		
					0.01,		
					0.01)


	#pTorp.SetDamage( GetDamage(pTorp) )
	pTorp.SetDamageRadiusFactor(0.13)
	pTorp.SetGuidanceLifetime( GetGuidanceLifetime() )
	pTorp.SetMaxAngularAccel( GetMaxAngularAccel() )

	# Multiplayer specific stuff.  Please, if you create a new torp
	# type. modify the SpeciesToTorp.py file to add the new type.
	import Multiplayer.SpeciesToTorp
	pTorp.SetNetType (Multiplayer.SpeciesToTorp.PHOTON)


        ## Add a creation handler to the torpedo :)
        LJTorpLib.LibTorp.AddCreationHandler(pTorp, __name__ + ".AttachSmoke") ### < If Missile dosnt have a tail comment this line out with a '#' symbol and uncoment the line bellow
        ##LJTorpLib.LibTorp.AddCreationHandler(pTorp, __name__ + ".SetDamage") ### < If Missile dosnt have a tail comment this line out with a '#' symbol and uncoment the line bellow
	return(0)

def AttachSmoke(self, pEvent = None):
    ## Attach Missile Effect
    pTorpedo = App.Torpedo_Cast(pEvent.GetDestination())
    if not pTorpedo:
        return (1)
    ## Create and Play a sequence
    LJTorpLib.LibTorp.SetupSmokeTrail(pTorpedo)

    SetDamage(pTorpedo) ## < - R.A This is where to add the code for a Missile with a Tail 

    return (0)

def SetDamage(self, pEvent = None):
    global sDamage

    pTorpedo = self
    if not pTorpedo:
        return (1)

    pTargetId = pTorpedo.GetTargetID()

    pSet = pTorpedo.GetContainingSet()

    lObjects = pSet.GetClassObjectList(App.CT_OBJECT)
    for sObject in lObjects:
	sOBjectID = sObject.GetObjID()

	if (sOBjectID == pTargetId):
		import Foundation
		import string
                if sObject.GetScript():
                        pShip = string.split(sObject.GetScript(), '.')[-1]

			if Foundation.shipList.has_key(pShip):
				pFoundationShip = Foundation.shipList[pShip]
				if pFoundationShip and hasattr(pFoundationShip, "fTorpedoID"):
					pTorpedoeID = pFoundationShip.fTorpedoID
					if (pTorpedoeID == "Not-Target"):
						Rand = App.g_kSystemWrapper.GetRandomNumber(100)

						if (Rand <= 5):
							pTorpedo.SetDamage(int(sDamage))
						
						else:
							pTorpedo.SetDamage(0.01) # <- R.A Keep this at 0.01 If its set to zero the torp will pass through the target no idea why
                                else: 
                                        pTorpedo.SetDamage(int(sDamage))

def GetLaunchSpeed():
	return(15.0)

def GetLaunchSound():
	return("MissileFire")

def GetPowerCost():
	return(30.0)

def GetName():
	return("Mark  Tacticals")

def GetDamage():
        global sDamage
	return int(sDamage)

def GetGuidanceLifetime():
	return 8.0

def GetMaxAngularAccel():
	return 2.0
