+ # Tries to simulate how we do it in the game
+ #
+ stack = [None]*64
+ stack_i = [0]*64
+ stack[0] = obj.cv_data.target
+ si = 1
+ loop_complete = False
+
+ while si > 0:
+ #{
+ if stack_i[si-1] == 2:
+ #{
+ si -= 1
+ continue
+
+ if si == 0: # Loop failed to complete
+ break
+ #}
+
+ node = stack[si-1]
+
+ targets = [None,None]
+ targets[0] = node.cv_data.target
+
+ if node.cv_data.classtype == 'classtype_route_node':
+ #{
+ targets[1] = node.cv_data.target1
+ #}
+
+ nextnode = targets[stack_i[si-1]]
+ stack_i[si-1] += 1
+
+ if nextnode != None: # branch
+ #{
+ if nextnode == stack[0]: # Loop completed
+ #{
+ loop_complete = True
+ break
+ #}
+
+ valid=True
+ for sj in range(si):
+ #{
+ if stack[sj] == nextnode: # invalidated path
+ #{
+ valid=False
+ break
+ #}
+ #}
+
+ if valid:
+ #{
+ stack_i[si] = 0
+ stack[si] = nextnode
+ si += 1
+ continue
+ #}
+ #}
+ #}
+
+ if loop_complete:
+ #{
+ cc = Vector((obj.cv_data.colour[0],\
+ obj.cv_data.colour[1],\
+ obj.cv_data.colour[2],\
+ 1.0))
+
+ for sj in range(si):
+ #{
+ sk = (sj+1)%si
+
+ if stack[sj].cv_data.classtype == 'classtype_gate' and \
+ stack[sk].cv_data.classtype == 'classtype_gate':
+ #{
+ dist = (stack[sj].location-stack[sk].location).magnitude
+ cv_draw_sbpath( stack[sj], stack[sk], cc*0.4, cc, dist, dist )
+ #}
+ else:
+ cv_draw_bpath( stack[sj], stack[sk], cc, cc )
+ #}
+
+ cv_view_course_i += 1
+ #}
+ #}
+
+ @staticmethod
+ def editor_interface( layout, obj ):
+ #{
+ layout.prop( obj.cv_data, "target", text="'Start' from" )
+ layout.prop( obj.cv_data, "colour" )
+ layout.prop( obj.cv_data, "strp", text="Name" )
+ #}
+#}
+
+# Classtype 12
+#
+# Purpose: links an mesh node to a type 11
+#
+class classtype_skin(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("skeleton",c_uint32)]
+
+ def encode_obj(_, node,node_def):
+ #{
+ node.classtype = 12
+
+ armature_def = node_def['linked_armature']
+ _.skeleton = armature_def['obj'].cv_data.uid
+ #}
+#}
+
+# Classtype 11
+#
+# Purpose: defines the allocation requirements for a skeleton
+#
+class classtype_skeleton(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("channels",c_uint32),
+ ("ik_count",c_uint32),
+ ("collider_count",c_uint32),
+ ("anim_start",c_uint32),
+ ("anim_count",c_uint32)]
+
+ def encode_obj(_, node,node_def):
+ #{
+ node.classtype = 11
+
+ _.channels = len( node_def['bones'] )
+ _.ik_count = node_def['ik_count']
+ _.collider_count = node_def['collider_count']
+ _.anim_start = node_def['anim_start']
+ _.anim_count = node_def['anim_count']
+ #}
+#}
+
+
+# Classtype 10
+#
+# Purpose: intrinsic bone type, stores collision information and limits too
+#
+class classtype_bone(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("flags",c_uint32),
+ ("ik_target",c_uint32),
+ ("ik_pole",c_uint32),
+ ("hitbox",(c_float*3)*2),
+ ("conevx",c_float*3),
+ ("conevy",c_float*3),
+ ("coneva",c_float*3),
+ ("conet",c_float)]
+
+ def encode_obj(_, node,node_def):
+ #{
+ node.classtype = 10
+
+ armature_def = node_def['linked_armature']
+ obj = node_def['bone']
+
+ _.flags = node_def['deform']
+
+ if 'ik_target' in node_def:
+ #{
+ _.flags |= 0x2
+ _.ik_target = armature_def['bones'].index( node_def['ik_target'] )
+ _.ik_pole = armature_def['bones'].index( node_def['ik_pole'] )
+ #}
+
+ # For ragdolls
+ #
+ if obj.cv_data.collider != 'collider_none':
+ #{
+ if obj.cv_data.collider == 'collider_box':
+ _.flags |= 0x4
+ else:
+ _.flags |= 0x8
+
+ _.hitbox[0][0] = obj.cv_data.v0[0]
+ _.hitbox[0][1] = obj.cv_data.v0[2]
+ _.hitbox[0][2] = -obj.cv_data.v1[1]
+ _.hitbox[1][0] = obj.cv_data.v1[0]
+ _.hitbox[1][1] = obj.cv_data.v1[2]
+ _.hitbox[1][2] = -obj.cv_data.v0[1]
+ #}
+
+ if obj.cv_data.con0:
+ #{
+ _.flags |= 0x100
+ _.conevx[0] = obj.cv_data.conevx[0]
+ _.conevx[1] = obj.cv_data.conevx[2]
+ _.conevx[2] = -obj.cv_data.conevx[1]
+ _.conevy[0] = obj.cv_data.conevy[0]
+ _.conevy[1] = obj.cv_data.conevy[2]
+ _.conevy[2] = -obj.cv_data.conevy[1]
+ _.coneva[0] = obj.cv_data.coneva[0]
+ _.coneva[1] = obj.cv_data.coneva[2]
+ _.coneva[2] = -obj.cv_data.coneva[1]
+ _.conet = obj.cv_data.conet
+ #}
+ #}
+#}
+
+# Classtype 100
+#
+# Purpose: sends a signal to another entity
+#
+class classtype_trigger(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("target",c_uint32)]
+
+ def encode_obj(_, node,node_def ):
+ #{
+ node.classtype = 100
+ if node_def['obj'].cv_data.target:
+ _.target = node_def['obj'].cv_data.target.cv_data.uid
+ #}
+
+ @staticmethod
+ def draw_scene_helpers( obj ):
+ #{
+ global cv_view_verts, cv_view_colours
+ cv_draw_ucube( obj.matrix_world, [0,1,0,1] )
+
+ if obj.cv_data.target:
+ cv_draw_arrow( obj.location, obj.cv_data.target.location, [1,1,1,1] )
+ #}
+
+ @staticmethod
+ def editor_interface( layout, obj ):
+ #{
+ layout.prop( obj.cv_data, "target", text="Triggers" )
+ #}
+#}
+
+# Classtype 101
+#
+# Purpose: Gives the player an achievement.
+# No cheating! You shouldn't use this entity anyway, since only ME can
+# add achievements to the steam ;)
+#
+class classtype_logic_achievement(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("pstr_name",c_uint32)]
+
+ def encode_obj(_, node,node_def ):
+ #{
+ node.classtype = 101
+ _.pstr_name = encoder_process_pstr( node_def['obj'].cv_data.strp )
+ #}
+
+ @staticmethod
+ def editor_interface( layout, obj ):
+ #{
+ layout.prop( obj.cv_data, "strp", text="Achievement ID" )
+ #}
+#}
+
+# Classtype 102
+#
+# Purpose: sends a signal to another entity
+#
+class classtype_logic_relay(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("targets",c_uint32*4)]
+
+ def encode_obj(_, node,node_def ):
+ #{
+ node.classtype = 102
+ obj = node_def['obj']
+ if obj.cv_data.target:
+ _.targets[0] = obj.cv_data.target.cv_data.uid
+ if obj.cv_data.target1:
+ _.targets[1] = obj.cv_data.target1.cv_data.uid
+ if obj.cv_data.target2:
+ _.targets[2] = obj.cv_data.target2.cv_data.uid
+ if obj.cv_data.target3:
+ _.targets[3] = obj.cv_data.target3.cv_data.uid
+ #}
+
+ @staticmethod
+ def draw_scene_helpers( obj ):
+ #{
+ global cv_view_verts, cv_view_colours
+
+ if obj.cv_data.target:
+ cv_draw_arrow( obj.location, obj.cv_data.target.location, [1,1,1,1] )
+ if obj.cv_data.target1:
+ cv_draw_arrow( obj.location, obj.cv_data.target1.location, [1,1,1,1] )
+ if obj.cv_data.target2:
+ cv_draw_arrow( obj.location, obj.cv_data.target2.location, [1,1,1,1] )
+ if obj.cv_data.target3:
+ cv_draw_arrow( obj.location, obj.cv_data.target3.location, [1,1,1,1] )
+ #}
+
+ @staticmethod
+ def editor_interface( layout, obj ):
+ #{
+ layout.prop( obj.cv_data, "target", text="Triggers" )
+ layout.prop( obj.cv_data, "target1", text="Triggers" )
+ layout.prop( obj.cv_data, "target2", text="Triggers" )
+ layout.prop( obj.cv_data, "target3", text="Triggers" )
+ #}
+#}
+
+# Classtype 14
+#
+# Purpose: Plays some audio (44100hz .ogg vorbis only)
+# NOTE: There is a 32mb limit on the audio buffer, world audio is
+# decompressed and stored in signed 16 bit integers (2 bytes)
+# per sample.
+#
+# volume: not used if has 3D flag
+# flags:
+# AUDIO_FLAG_LOOP 0x1
+# AUDIO_FLAG_ONESHOT 0x2 (DONT USE THIS, it breaks semaphores)
+# AUDIO_FLAG_SPACIAL_3D 0x4 (Probably what you want)
+# AUDIO_FLAG_AUTO_START 0x8 (Play when the world starts)
+# ......
+# the rest are just internal flags, only use the above 3.
+#
+class classtype_audio(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("pstr_file",c_uint32),
+ ("flags",c_uint32),
+ ("volume",c_float)]
+
+ def encode_obj(_, node,node_def ):
+ #{
+ node.classtype = 14
+
+ obj = node_def['obj']
+
+ _.pstr_file = encoder_process_pstr( obj.cv_data.strp )
+
+ flags = 0x00
+ if obj.cv_data.bp0: flags |= 0x1
+ if obj.cv_data.bp1: flags |= 0x4
+ if obj.cv_data.bp2: flags |= 0x8
+
+ _.flags = flags
+ _.volume = obj.cv_data.fltp
+ #}
+
+ @staticmethod
+ def editor_interface( layout, obj ):
+ #{
+ layout.prop( obj.cv_data, "strp" )
+
+ layout.prop( obj.cv_data, "bp0", text = "Looping" )
+ layout.prop( obj.cv_data, "bp1", text = "3D Audio" )
+ layout.prop( obj.cv_data, "bp2", text = "Auto Start" )
+ #}
+
+ @staticmethod
+ def draw_scene_helpers( obj ):
+ #{
+ global cv_view_verts, cv_view_colours
+
+ cv_draw_sphere( obj.location, obj.scale[0], [1,1,0,1] )
+ #}
+#}
+
+# Classtype 200
+#
+# Purpose: world light
+#
+class classtype_world_light( Structure ):
+#{
+ _pack_ = 1
+ _fields_ = [("type",c_uint32),
+ ("colour",c_float*4),
+ ("angle",c_float)]
+
+ def encode_obj(_, node, node_def):
+ #{
+ node.classtype = 200
+
+ obj = node_def['obj']
+ data = obj.data
+ _.colour[0] = data.color[0]
+ _.colour[1] = data.color[1]
+ _.colour[2] = data.color[2]
+ _.colour[3] = data.energy
+
+ if obj.data.type == 'POINT':
+ #{
+ _.type = 0
+ _.angle = 0.0
+ #}
+ elif obj.data.type == 'SPOT':
+ #{
+ _.type = 1
+ _.angle = math.cos(data.spot_size*0.5)
+ #}
+ #}
+
+ @staticmethod
+ def editor_interface( layout, obj ):
+ #{
+ pass
+ #}
+#}
+
+# Classtype 201
+#
+# Purpose: lighting settings for world
+#
+class classtype_lighting_info(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("colours",(c_float*3)*3),
+ ("directions",(c_float*2)*3),
+ ("states",c_uint32*3),
+ ("shadow_spread",c_float),
+ ("shadow_length",c_float),
+ ("ambient",c_float*3)]
+
+ def encode_obj(_, node, node_def):
+ #{
+ node.classtype = 201
+
+ # TODO
+ #}
+
+ @staticmethod
+ def editor_interface( layout, obj ):
+ #{
+ pass
+ #}
+#}
+
+class classtype_spawn_link(Structure):
+#{
+ _pack_ = 1
+ _fields_ = [("connections",c_uint32*4)]
+
+ def encode_obj(_, node,node_def ):
+ #{
+ node.classtype = 0
+ #}
+
+ @staticmethod
+ def editor_interface( layout, obj ):
+ #{
+ pass
+ #}
+
+ @staticmethod
+ def draw_scene_helpers( obj ):
+ #{
+ global cv_view_verts, cv_view_colours
+
+ count = 0
+
+ for obj1 in bpy.context.collection.objects:
+ #{
+ if (obj1.cv_data.classtype != 'classtype_spawn_link') and \
+ (obj1.cv_data.classtype != 'classtype_spawn') :
+ continue
+
+ if (obj1.location - obj.location).length < 40.0:
+ #{
+ cv_draw_line( obj.location, obj1.location, [1,1,1,1] )
+ count +=1
+ #}