######################################
#                                    #
#       URU Properties class         #
#                                    #
######################################
#
######################################
# By Sjaak-de-Draak                  #
######################################
#
import Blender

import math
from math import *

class URUProperties:
    __module__ = __name__
    __module__ = __name__

    # Function to initialize the class
    #
    def __init__(self, name='URUProperties'):
        self.className = name
        self.classType = 'URUProperties'
        #
        # Set the basic propety variables and defaults
        #
        self.nameScheme = "default"
        self.customName = "custom"
        #
        self.defaultProperties()
        #
        #self.defaultProp = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5 ]
	# adding ladder support
        self.defaultProp = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]
        #
        self.properties = self.defaultProp
        #
        #self.AlcSpecialList = [ "none", "point", "footsteprgn", "swimrgn", "swimplainsfc", "StraightCurrent", "CircularCurrent" ]
        self.AlcSpecialList = [ "none", "point", "footsteprgn", "swimrgn", "swimplainsfc", "swimscursfc", "swimccursfc", "paniclnkgrn", "climbregion", "clickregion" ]
        # Now to define some already known PropertyTypes
        self.definePropertyTypes()
        #
        #
        self.debug = 0
        self.verbose = 0

    def setDebug(self):
        self.debug = 1

    def setVerbose(self):
        self.verbose = 1

    def getAlcSpecialList(self):
        return self.AlcSpecialList

    def setStates(self,state=0):
        #
        # Set the propety state variables (ON or OFF)
        #
        self.name[3]            = state
        self.page_num[3]        = state
        self.alctype[3]            = state
        self.alcspecial[3]        = state
        self.footstepsound[3]        = state
        self.col_type[3]        = state
        self.mass[3]            = state
        self.rc[3]            = state
        self.el[3]            = state
        self.light[3]            = state
        self.material[3]        = state
        self.col_flags0[3]        = state
        self.col_flags1[3]        = state
        self.col_flags2[3]        = state
        self.col_flags3[3]        = state
        self.col_flags4[3]        = state
        self.col_flags5[3]        = state
        self.currentdummy[3]        = state
        self.swimsfc_f1[3]        = state
        self.swimsfc_f2[3]        = state
        self.swimsfc_f3[3]        = state
        self.swimsfc_f4[3]        = state
        self.swimsfc_f5[3]        = state
        self.bottomflag[3]	= state 
        self.climboffset[3] 	= state
        self.climbheight[3]	= state

    # Function to set the default PropertyTypes
    #
    def defaultProperties(self):
        #
        # Set the basic propety variables and defaults
        #
        self.name         = [ "name",        "default",    "STRING",    1 ]
        self.page_num         = [ "page_num",        "0",        "STRING",    1 ]
        self.alctype         = [ "alctype",        "object",    "STRING",    1 ]
        self.alcspecial        = [ "alcspecial",    "none",        "STRING",    0 ]
        self.footstepsound    = [ "footstepsound",    19,        "STRING",    0 ]
        self.col_type         = [ "col_type",        "4",        "STRING",    1 ]
        self.mass         = [ "mass",        0.000,        "FLOAT",    1 ]
        self.rc         = [ "rc",        0.000,        "FLOAT",    1 ]
        self.el         = [ "el",        0.000,        "FLOAT",    1 ]
        self.light        = [ "light",        "00000000",    "STRING",    1 ]
        self.material         = [ "material",        "material",    "STRING",    1 ]
        self.col_flags0     = [ "col_flags0",    "0200",        "STRING",    1 ]
        self.col_flags1     = [ "col_flags1",    "00000000",    "STRING",    1 ]
        self.col_flags2     = [ "col_flags2",    "02000000",    "STRING",    1 ]
        self.col_flags3     = [ "col_flags3",    "0000",        "STRING",    1 ]
        self.col_flags4     = [ "col_flags4",    "00000000",    "STRING",    1 ]
        self.col_flags5     = [ "col_flags5",    "00000000",    "STRING",    1 ]
        self.currentdummy     = [ "currentdummy",    "SwimCurrentDummy","STRING",    0 ]
        self.swimsfc_f1        = [ "swimsfc_f1",    0.000,        "FLOAT",    0 ]
        self.swimsfc_f2        = [ "swimsfc_f2",    0.000,        "FLOAT",    0 ]
        self.swimsfc_f3        = [ "swimsfc_f3",    0.000,        "FLOAT",    0 ]
        self.swimsfc_f4        = [ "swimsfc_f4",    0.000,        "FLOAT",    0 ]
        self.swimsfc_f5        = [ "swimsfc_f5",    0.000,        "FLOAT",    0 ]
        self.bottomflag        = [ "bottomFlag",    1,            "INT",      0 ]
        self.climboffset       = [ "climbOffset",   0,            "INT",      0 ]
        self.climbheight       = [ "climbHeight",   4,            "INT",      0 ]


    # Function to define some builtin class PropertyTypes
    #
    def definePropertyTypes(self):

        # SfxRegSen
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        self.alcspecial[1]    = "none"
        self.footstepsound[3]    = 0
        self.mass[1] = 1.000            # needs some mass
        self.col_flags0[1] = "0400"        # GUI/Game mode
        self.col_flags1[1] = "08000000"    # Detect stuff
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.SfxRegSen = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        # GenDetReg
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        self.alcspecial[1]    = "none"
        self.footstepsound[3]    = 0
        self.col_type[1] = "3"            # use the faces of the 'Convex Hull' as collision data
        self.mass[1] = 1.000            # needs some mass
        self.col_flags0[1] = "0400"        # GUI/Game mode
        self.col_flags1[1] = "08000000"    # Detect stuff
        self.col_flags2[1] = "00000000"    # nada
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.col_flags5[1] = "00000000"    # nada
        self.GenDetReg = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        # LdrBottom
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        self.alcspecial[1]    = "climbregion"
        self.footstepsound[3]    = 0
        self.col_type[1] = "3"            # use the faces of the 'Convex Hull' as collision data
        self.mass[1] = 1.000            # needs some mass
        self.col_flags0[1] = "0400"        # enable collision (no save)
        self.col_flags1[1] = "08000000"    # Detect stuff
        self.col_flags2[1] = "00000000"    # nada
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.col_flags5[1] = "00000000"    # nada
        self.bottomflag[1] = 1
        self.climboffset[1] = 0
        self.climbheight[1] = 4
        self.LdrBottom = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]


        # LdrBounds
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        self.alcspecial[1]    = "none"
        self.footstepsound[3]    = 0
        self.col_type[1] = "3"            # use the faces of the 'Convex Hull' as collision data
        self.mass[1] = 1.000            # needs some mass
        self.col_flags0[1] = "0200"        # enable collision (no save)
        #self.col_flags0[1] = "0002"        # ???
        self.col_flags1[1] = "00000000"    # nada
        self.col_flags2[1] = "00020000"    # (make Avatar (and/or) Camera) Follow??
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.col_flags5[1] = "00000000"    # nada
        self.LdrBounds = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5 , self.bottomflag, self.climboffset, self.climbheight]

        # LdrTop
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        self.alcspecial[1]    = "climbregion"
        self.footstepsound[3]    = 0
        self.col_type[1] = "3"            # use the faces of the 'Convex Hull' as collision data
        self.mass[1] = 1.000            # needs some mass
        self.col_flags0[1] = "0400"        # enable collision (no save)
        self.col_flags1[1] = "08000000"    # Detect stuff
        self.col_flags2[1] = "00000000"    # 
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.col_flags5[1] = "00000000"    # nada
        self.bottomflag[1] = 0
        self.climboffset[1] = 0
        self.climbheight[1] = 4
        self.LdrTop = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]


        # CollObj
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        self.footstepsound[3]    = 0
        self.mass[1] = 1.000            # needs some mass
        self.rc[1] = 0.500                # needs some friction
        self.col_flags0[1] = "0200"        # enable collision (no save)
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.col_flags5[1] = "00000044"    # flags: CameraAvoid | DisableFriction
        self.CollObj = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        # GenObjWC
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "object"        # collider type (visible)
        self.footstepsound[3]    = 0
        self.rc[1] = 4.000                # needs some friction
        self.col_flags0[1] = "0200"        # Enables collision with avatars - object state is NOT saved 
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.col_flags5[1] = "00000044"    # flags: CameraAvoid | DisableFriction
        self.GenObjWC = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        # GenObjNC
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "object"        # collider type (visible)
        self.footstepsound[3]    = 0
        self.mass[1] = 1.000            # needs some mass
        self.col_flags0[1] = "0002"        # ???
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.col_flags5[1] = "00000040"    # flag(s): CameraAvoid
        self.GenObjNC = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        # Kickable
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "object"        # collider type (visible)
        self.footstepsound[3]    = 0
        self.mass[1] = 2.000            # needs some mass
        self.rc[1] = 4.000            # needs some friction
        self.col_flags0[1] = "0100"        # Enables collision with avatars - object state is saved into the age sav
        self.col_flags5[1] = "00000040"    # flags: CameraAvoid 
        self.Kickable = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        # SfxFootstepRegSen
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        self.alcspecial[1]    = "footsteprgn"
        self.footstepsound[1]    = 0
        self.mass[1] = 1.000            # needs some mass
        self.col_flags0[1] = "0400"        # GUI/Game mode
        self.col_flags1[1] = "08000000"    # Detect stuff
        self.col_flags2[1] = "00000000"    # 
        self.col_flags3[1] = "0000"        # 
        self.col_flags4[1] = "00000004"    # kPinned  (doesn't move)
        self.col_flags5[1] = "00000000"    # 
        self.SfxFtRegSen = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        # SwimRegSen
        #
        # This is a swim region (force Avatar Swim animations) (should be inside the Master SwimRegion (SwimDetRegSen) )
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        #self.alcspecial[1]    = "swimplainsfc"
        self.alcspecial[1]    = "swimscursfc" # default to straight swim current type
        self.col_type[1] = "4"            # use the faces of the 'Convex Hull' as collision data
        self.footstepsound[1]    = 18
        self.footstepsound[3]    = 0
        self.mass[1] = 0.000            # needs NO mass
        self.col_flags0[1] = "0000"        # 
        self.col_flags1[1] = "00000000"    # Detect stuff ???
        self.col_flags2[1] = "00000000"    # 
        self.col_flags3[1] = "0000"        # 
        self.col_flags4[1] = "00000000"    # 
        self.col_flags5[1] = "00000080"    # Swim detection region?
        self.currentdummy[1] = "SwimCurrentDummy" #needed (possibly the name relates to the name of the currentdummy point)
        self.swimsfc_f1[1] = 0.000    # Horizontal current force (and direction) ( <= - & + => )
        self.swimsfc_f2[1] = 0.000    # Water flow/foam type (not sure)
        self.swimsfc_f3[1] = 0.000    # Vertical current force Below SwimCurrentDummy point ( v - & + ^ )
        self.swimsfc_f4[1] = 0.000    # Water flow/foam type (not sure)
        self.swimsfc_f5[1] = 0.000    # Vertical current force Above SwimCurrentDummy point ( v - & + ^ )
        self.SwimRegSen = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        # SwimDetRegSen
        #
        # This is the Master SwimRegion
        #
        self.defaultProperties()            # set the defaults first
        self.alctype[1] = "collider"    # collider type (invisible)
        self.alcspecial[1]    = "swimrgn"
        self.col_type[1] = "1"            # use the faces of the 'Convex Hull' as collision data
        self.footstepsound[1]    = 2
        self.footstepsound[3]    = 0
        self.mass[1] = 0.000            # needs NO mass
        self.col_flags0[1] = "0000"        # Swim/Special mode
        self.col_flags1[1] = "00020000"    # Detect stuff (MasterSwimRegion)
        self.col_flags2[1] = "00000000"    # 
        self.col_flags3[1] = "0000"        # 
        self.col_flags4[1] = "00000000"    # 
        self.col_flags5[1] = "00000000"    # 
        self.SwimDetRegSen = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]


        # Clickable
        #
        self.defaultProperties()            	# set the defaults first
        self.alctype[1] = "collider"        	# collider type (invisible)
        self.alcspecial[1]    = "clickregion"	# mark as Clickable region
        self.footstepsound[3]    = 0
        self.mass[1] = 1.000			# needs some mass
        self.rc[1] = 0.000			# needs NO friction
        self.col_flags0[1] = "0400"        	# GUI/Game mode
        self.col_flags1[1] = "08000000"    	# Detect stuff
        self.col_flags2[1] = "00000000"    	# 
        self.col_flags3[1] = "0000"        	# 
        self.col_flags4[1] = "00000004"    	# kPinned  (doesn't move)
        self.col_flags5[1] = "00000000"    	#  
        self.Clickable = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]


    # Function to alter property value(s)
    #
    # it assumes properties will be a list item containing one or more properties 
    #
    def alterProperties(self, propertiesList = None):
        if (propertiesList == None):
            if self.debug: print "\nNo property provided, bailing.....\n"
            return 1
        self.setStates(0)
        # parse the list
        for property in propertiesList:
            # check which property we are dealing with and act accordingly
            if self.debug: print "Checking which property is being altered"

            if (property[0] == "name"):
                self.name[1] = "%s" % property[1]
                self.name[3] = property[3]
            elif (property[0] == "page_num"):
                self.page_num[1] = "%s" % property[1]
                self.page_num[3] = property[3]
            elif (property[0] == "alctype"):
                self.alctype[1] = "%s" % property[1]
                self.alctype[3] = property[3]
            elif (property[0] == "alcspecial"):
                self.alcspecial[1] = "%s" % property[1]
                #self.alcspecial[1] = "%s" % ( self.AlcSpecialList[(property[1])] )
                self.alcspecial[3] = property[3]
            elif (property[0] == "footstepsound"):
                #self.footstepsound[1] = "%d" % property[1]
                self.footstepsound[1] = property[1]
                self.footstepsound[3] = property[3]
            elif (property[0] == "col_type"):
                self.col_type[1] = "%s" % property[1]
                self.col_type[3] = property[3]
            elif (property[0] == "mass"):
                self.mass[1] = float(property[1])
                self.mass[3] = property[3]
            elif (property[0] == "rc"):
                self.rc[1] = float(property[1])
                self.rc[3] = property[3]
            elif (property[0] == "el"):
                self.el[1] = float(property[1])
                self.el[3] = property[3]
            elif (property[0] == "light"):
                self.light[1] = "%s" % property[1]
                self.light[3] = property[3]
            elif (property[0] == "material"):
                self.material[1] = "%s" % property[1]
                self.material[3] = property[3]
            elif (property[0] == "col_flags0"):
                self.col_flags0[1] = "%s" % property[1]
                self.col_flags0[3] = property[3]
            elif (property[0] == "col_flags1"):
                self.col_flags1[1] = "%s" % property[1]
                self.col_flags1[3] = property[3]
            elif (property[0] == "col_flags2"):
                self.col_flags2[1] = "%s" % property[1]
                self.col_flags2[3] = property[3]
            elif (property[0] == "col_flags3"):
                self.col_flags3[1] = "%s" % property[1]
                self.col_flags3[3] = property[3]
            elif (property[0] == "col_flags4"):
                self.col_flags4[1] = "%s" % property[1]
                self.col_flags4[3] = property[3]
            elif (property[0] == "col_flags5"):
                self.col_flags5[1] = "%s" % property[1]
                self.col_flags5[3] = property[3]
            elif (property[0] == "currentdummy"):
                self.currentdummy[1] = "%s" % property[1]
                self.currentdummy[3] = property[3]
            elif (property[0] == "swimsfc_f1"):
                self.swimsfc_f1[1] = property[1]
                self.swimsfc_f1[3] = property[3]
            elif (property[0] == "swimsfc_f2"):
                self.swimsfc_f2[1] = property[1]
                self.swimsfc_f2[3] = property[3]
            elif (property[0] == "swimsfc_f3"):
                self.swimsfc_f3[1] = property[1]
                self.swimsfc_f3[3] = property[3]
            elif (property[0] == "swimsfc_f4"):
                self.swimsfc_f4[1] = property[1]
                self.swimsfc_f4[3] = property[3]
            elif (property[0] == "swimsfc_f5"):
                self.swimsfc_f5[1] = property[1]
                self.swimsfc_f5[3] = property[3]
            elif (property[0] == "bottomFlag"):
                self.bottomflag[1] = int(property[1])
                self.bottomflag[3] = property[3]
            elif (property[0] == "climbOffset"):
                self.climboffset[1] = property[1]
                self.climboffset[3] = property[3]
            elif (property[0] == "climbHeight"):
                self.climbheight[1] = property[1]
                self.climbheight[3] = property[3]
            else:
                if self.verbose or self.debug: print "Unknown property: %s" % property
                continue

            if self.debug: print "Altered: %s" % property

    # Function to fetch Custom URU Properties
    #
    # it assumes the user (read: menu) will provide the correct values string 
    #
    def fetchCustomProperties(self, propertiesList = None):
        if (propertiesList == None):
            if self.debug: print "\nNo property provided, bailing.....\n"
            return 1

        self.alterProperties(propertiesList)

        self.Custom = [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

        return self.Custom


    # Function to fetch known (named) URU Properties
    #
    # it assumes the user (read: menu) will provide the correct string 
    #
    def fetchBuiltinProperty(self, propertyType = None):
        if (propertyType != "Custom"):        # the only exception
            # set the default propertie 1st (just to make sure)
            self.definePropertyTypes()
        if (propertyType == None):
            if self.debug: print "No propertyType provided ... getting the (class) default"
            return self.defaultProp
        elif (propertyType == "SfxRegSen"):        # it's a Sound Region Sensor
            if self.debug: print "Returning %s properties" % propertyType
            return self.SfxRegSen 
        elif (propertyType == "GenDetReg"):        # it's a Generic Detector Region (cam, marker, ladder .. etc)
            if self.debug: print "Returning %s properties" % propertyType
            return self.GenDetReg 
        elif (propertyType == "LdrBottom"):        # Bottom of Ladder anim
            if self.debug: print "Returning %s properties" % propertyType
            return self.LdrBottom 
        elif (propertyType == "LdrBounds"):        # This is THE avatar/camera to Ladder Binding object/mesh
            if self.debug: print "Returning %s properties" % propertyType
            return self.LdrBounds 
        elif (propertyType == "LdrTop"):        # Top of Ladder anim 
            if self.debug: print "Returning %s properties" % propertyType
            return self.LdrTop 
        elif (propertyType == "CollObj"):        # it's a Collision(only) Object (invisible)
            if self.debug: print "Returning %s properties" % propertyType
            return self.CollObj
        elif (propertyType == "GenObjWC"):        # it's a Generic Object (With Collision)
            if self.debug: print "Returning %s properties" % propertyType
            return self.GenObjWC
        elif (propertyType == "GenObjNC"):        # it's a Generic Object (No Collision)
            if self.debug: print "Returning %s properties" % propertyType
            return self.GenObjNC
        elif (propertyType == "Kickable"):        # it's a Generic Kickable Object (With Collision (ofcourse;))
            if self.debug: print "Returning %s properties" % propertyType
            return self.Kickable
        elif (propertyType == "SfxFtRegSen"):        # it's a Sound Region Sensor
            if self.debug: print "Returning %s properties" % propertyType
            return self.SfxFtRegSen 
        elif (propertyType == "SwimRegSen"):        # it's a Swim Region Sensor
            if self.debug: print "Returning %s properties" % propertyType
            return self.SwimRegSen 
        elif (propertyType == "SwimDetRegSen"):        # it's a Swim action/Detection Region Sensor
            if self.debug: print "Returning %s properties" % propertyType
            return self.SwimDetRegSen 
        elif (propertyType == "Clickable"):        # it's a Clickable Region (With Collision???)
            if self.debug: print "Returning %s properties" % propertyType
            return self.Clickable
        elif (propertyType == "Custom"):        # it's a User Defined property list
            if self.debug: print "Returning %s properties" % propertyType
            return self.Custom
        else:
            if self.debug: print "Unknown propertyType: %s" % propertyType
            return None


    # Function to fetch URU Properties from a selected object
    #
    # it assumes the user will select the appropriate item (as 1st selection item) 
    #
    def fetchSelectedProperties(self):
        selected = Blender.Object.GetSelected()
        if (selected == None):
            if self.verbose: print "No object selected"
            return None
        # reset to defaults (so all objects become inactive)
        self.defaultProperties()
        # pick the 1st selected object and display it's properties
        try:
            properties = selected[0].getAllProperties()
        except:
            print "Failed to fetch properties Line 494 in fetchSelectedProperties() in URUProperties_class_10x.py"
            fetchedProperties = [] 
            return fetchedProperties
        fetchedProperties = [] 
        for property in properties:
            if (property.getName() == "footstepsound"):
                fetchedProperties.append([property.getName(), int(property.getData(),16), property.getType(), 1])
            else:
                fetchedProperties.append([property.getName(), property.getData(), property.getType(), 1])
        if self.debug: print "I fetched: %s " % fetchedProperties
        return fetchedProperties

    # Function to set URU Properties for a provided object
    #
    # it assumes the user/class will supply the list of properties 
    #
    def setProperty(self, obj = None , properties = [], mask = 0):

        if (obj == None):
            if self.debug: print "\nNo Object(s) provided, bailing...\n"
            return 1

        if self.verbose: print "\nSetting properties for object: %s" % obj

        for propertyData in properties:
            # check for mask flag (if set then don't remove properties)
            if (mask and (propertyData[3]==0)):
                if self.debug: print "importing property: %s  (Mask flag is set)" % propertyData[0]
                try:
                    objProperties = obj.getAllProperties()
                    for property in objProperties:
                        if (property.getName() == propertyData[0]):
                            propertyData[0] = property.getName()
                            propertyData[1] = property.getData()
                            propertyData[2] = property.getType()
                            propertyData[3] = 2
                except:
                    if self.debug: print "import of: %s failed" % propertyData[0]
	    # now we can safly remove the object (thus keeping the correct order)
            try:
                obj.removeProperty((obj.getProperty(propertyData[0])))
                if self.debug: print "Removed property: %s  (before re-adding it)" % propertyData
            except:
                if self.debug: print "Couldn't remove property: %s  (probably hasn't been added (yet))" % propertyData

            # do the regular stuff
            if (propertyData[3] or ((propertyData[3] > 1) and mask)):
                if (propertyData[0]=="footstepsound"):
                    if ( propertyData[1] > 15 ):
                        obj.addProperty(propertyData[0], ("%2X" % propertyData[1]), propertyData[2])
                    else:
                        obj.addProperty(propertyData[0], ("0%1X" % propertyData[1]), propertyData[2])
                else:
                    obj.addProperty(propertyData[0], propertyData[1], propertyData[2])
                if self.debug: print "(re)Added property:  %s " % propertyData
            else:
                if self.debug: print "NOT Adding property: %s " % propertyData




    # for this function we'll be expecting a list of selected Objects to be provided by Blender (selected by the user ofcourse)
    #
    # the user can also provide a (custom)propertyType to be applied (will be menu driven)
    #
    def setUruPropertiesForSelectedObjects(self, propertyType=None, propertiesList=None, mask=0):

        if (propertyType == None):
            if self.verbose: print "\n\nNo user properties provided, going with the defaults\n"
            self.defaultProperties()
        else:
            if (propertiesList == None):
                propertiesList = self.fetchBuiltinProperty(propertyType)
            if (propertiesList == None):
                self.defaultProperties()
            else:
                self.alterProperties(propertiesList)
            
        selected = Blender.Object.GetSelected()
        numSelected = len(selected)  
        for obj in selected:
            # check if the object is a Mesh
            data = obj.getData()
            if self.debug: print type(data)
            #if type(data) != Blender.Types.NMeshType:
            #    if self.debug: print "Object: '%s' is not an NMesh, moving on..." % obj.getName()
            #    continue
            #
            # Hey it shouldn't matter if it's not an NMesh (you are still in stair mode you fool ;)
            #
            if self.verbose: print "Setting URU properties for Object: '%s'" % obj.getName()

            # Get the name of the Object and set the name field in the properties accordingly
            #if (self.name[1] == "default"):
            if (self.nameScheme == "default"):
                self.name[1] = obj.getName()
            else:
                # set the name provided by the user
                # but if there are multiple objects selected we'll need a customized name
                if self.debug: print "Number of selected objects: %d" % numSelected
                if ( numSelected > 1 ):
                    # make 'em unique
                    for property in propertiesList:
                        if (property[0] == "name"):
                            #name = ("%s_%s" % (property[1], obj.getName()))
                            name = ("%s_%s" % (self.customName, obj.getName()))
                            self.name[1] = name
                            break
                else:
                    # use the 'exact' user defined name
                    #for property in propertiesList:
                    #    if (property[0] == "name"):
                    #        name = property[1]
                    #        self.name[1] = name
                    #        break
                    self.name[1] = self.customName


            # TODO: check for linked objects (and/or) materials
            if (self.material[1] == "default"):
                # set the objects own name
                self.material[1] = obj.getName()
            elif(self.material[1] == "material" or self.material[1] == "Material"):
                # set the name of the first material of this object
                # but be careful the object is a Mesh and actually has a material assigned to it
                if (obj.getType() == 'Mesh'):
                    #materialList = obj.getMaterials(1)    # call with nonzero value to get None returned for empty material slots
                    # that doesn't work, need to get the object data 1st
                    data = obj.getData()
                    materialList = data.getMaterials(1)    # call with nonzero value to get None returned for empty material slots
                    #if self.debug: print "Materials: %s" % obj.getMaterials(1)    # call with nonzero value to get None returned for empty material slots
                    #if self.debug: print "ObjData: %s" % data    # call with nonzero value to get None returned for empty material slots
                    if self.debug: print "ObjDataMaterials: %s" % data.getMaterials(1)    # call with nonzero value to get None returned for empty material slots
                    if self.debug: print Blender.Material.Get()
                    for material in materialList:
                        if (material != None):
                            self.material[1] = material.getName()  # get the name of the material
                            break   # only do the 1st item and bail (for now)
                else:
                    # set the objects own name
                    self.material[1] = obj.getName()
            elif (self.material[1] == "parent" or self.material[1] == "Parent" ):
                print "TODO: get the Material name of the 'parent' object"
                parent = obj.getParent()
                if ( parent != None ):
                    parentData = parent.getData()
                    materialList = parentData.getMaterials(1)    # call with nonzero value to get None returned for empty material slots
                    for material in materialList:
                        if (material != None):
                            self.material[1] = material.getName() # and (finally) set the name of the (parent object) material
                            break
                    # if we end up here it means there is NO material assigned 
                    # set the objects own name
                    self.material[1] = obj.getName()
                else:
                    # there is NO parent object
                    # set the objects own name
                    self.material[1] = obj.getName()
            else:
                # set the material name provided by the user
                for property in propertiesList:
                    if (property[0] == "material"):
                        #self.material[1] = property[1]
            # holy crap going with the object name
                        self.material[1] = obj.getName()

            # example 
            # [name, page_num, alctype, self.alcspecial, self.footstepsound, col_type, mass, rc, el, light, material, col_flags0, col_flags1, col_flags2, col_flags3, col_flags4, col_flags5 ]
            #    0       1        2            3                    4            5       6    7   8    9       10          11          12          13          14          15          16

            propertiesList =  [self.name, self.page_num, self.alctype, self.alcspecial, self.footstepsound, self.col_type, self.mass, self.rc, self.el, self.light, self.material, self.col_flags0, self.col_flags1, self.col_flags2, self.col_flags3, self.col_flags4, self.col_flags5, self.currentdummy, self.swimsfc_f1, self.swimsfc_f2, self.swimsfc_f3, self.swimsfc_f4, self.swimsfc_f5, self.bottomflag, self.climboffset, self.climbheight ]

            # and send them away for processing
            self.setProperty(obj, propertiesList,mask)
