コード例 #1
0
ファイル: fsmtargets.py プロジェクト: xuebai5/TheZombieEngine
 def refresh_current_target(self, target_index):
     transition = self.__get_transition()
     state_gui_name = fsmstates.get_state_gui_name(
         transition.gettargetstatebyindex( target_index ).getfullname() )
     probability = transition.gettargetprobabilitybyindex( target_index )
     self.list_targets.SetStringItem( target_index, 0, state_gui_name )
     self.list_targets.SetStringItem( target_index, 1, str(probability) + "%" )
     self.__update_total_probability()
コード例 #2
0
ファイル: fsmtargets.py プロジェクト: xuebai5/TheZombieEngine
 def refresh_current_target(self, target_index):
     transition = self.__get_transition()
     state_gui_name = fsmstates.get_state_gui_name(
         transition.gettargetstatebyindex(target_index).getfullname())
     probability = transition.gettargetprobabilitybyindex(target_index)
     self.list_targets.SetStringItem(target_index, 0, state_gui_name)
     self.list_targets.SetStringItem(target_index, 1,
                                     str(probability) + "%")
     self.__update_total_probability()
コード例 #3
0
def find_transition_condition(condition_class):
    columns = ['FSM', 'State', 'Transition']
    rows = []
    
    # Look for the condition in all the FSMs
    fsm_paths = fsm.get_fsms()
    for fsm_path in fsm_paths:
        state_mc = pynebula.lookup( fsm_path )
        
        # Look for the condition in all the script transitions of 
        # the FSM (and event filters)
        state_paths = fsm.get_states( state_mc.getfullname() )
        for state_path in state_paths:
            trans_paths = fsm.get_transitions( state_path )
            for trans_path in trans_paths:
                trans = pynebula.lookup( trans_path )
                trans_cond = trans.getcondition()
                if trans_cond.isa( str(condition_class) ):
                    rows.append( [
                        state_mc.getname(),
                        fsmstates.get_state_gui_name(
                            state_path 
                            ),
                        fsmtransitions.get_transition_gui_name(
                            trans_path 
                            )
                        ] )
                elif trans_cond.isa('neventcondition'):
                    filter_cond = trans_cond.getfiltercondition()
                    if filter_cond is not None:
                        if filter_cond.isa( str(condition_class) ):
                            rows.append( [
                                state_mc.getname(),
                                fsmstates.get_state_gui_name(
                                    state_path 
                                    ),
                                fsmtransitions.get_transition_gui_name(
                                    trans_path 
                                    )
                                ] )
    
    return (columns, rows)
コード例 #4
0
 def __find_selector(self, sm, selector, log):
     # Look for the FSM selector in all the state nodes of the FSM
     state_paths = fsm.get_states( sm.getfullname() )
     for state_path in state_paths:
         state = pynebula.lookup( state_path )
         if state.isa('nnodestate'):
             if state.getfsmselector() == selector:
                 log.append( [
                     sm.getname(),
                     fsmstates.get_state_gui_name( state_path )
                     ] )
コード例 #5
0
 def __find_condition(self, sm, condition, log):
     # Look for the condition in all the script transitions of the FSM (and event filters)
     state_paths = fsm.get_states( sm.getfullname() )
     for state_path in state_paths:
         trans_paths = fsm.get_transitions( state_path )
         for trans_path in trans_paths:
             trans = pynebula.lookup( trans_path )
             trans_cond = trans.getcondition()
             if condition == trans_cond:
                 log.append( [
                     sm.getname(),
                     fsmstates.get_state_gui_name( state_path ),
                     fsmtransitions.get_transition_gui_name( trans_path )
                     ] )
             elif trans_cond.isa('neventcondition'):
                 if condition == trans_cond.getfiltercondition():
                     log.append( [
                         sm.getname(),
                         fsmstates.get_state_gui_name( state_path ),
                         fsmtransitions.get_transition_gui_name( trans_path )
                         ] )
コード例 #6
0
ファイル: fsmtargets.py プロジェクト: xuebai5/TheZombieEngine
 def __on_new_target(self, event):
     """Create a new target with default values"""
     # Create a transition to the first free target state by default
     state = pynebula.lookup(get_free_targets(self.transition_path)[0])
     probability = 100
     self.__get_transition().addtarget(state, probability)
     index = self.list_targets.GetItemCount()
     gui_name = fsmstates.get_state_gui_name(state.getfullname())
     self.list_targets.InsertStringItem(index, gui_name)
     self.list_targets.SetStringItem(index, 1, str(probability) + "%")
     self.__update_total_probability()
     self.__update_new_button()
     fsmevents.signal_fsm_change(self, fsmevents.ID_NewTarget)
コード例 #7
0
ファイル: fsmtargets.py プロジェクト: xuebai5/TheZombieEngine
 def __on_new_target(self, event):
     """Create a new target with default values"""
     # Create a transition to the first free target state by default
     state = pynebula.lookup( get_free_targets(self.transition_path)[0] )
     probability = 100
     self.__get_transition().addtarget( state, probability )
     index = self.list_targets.GetItemCount()
     gui_name = fsmstates.get_state_gui_name( state.getfullname() )
     self.list_targets.InsertStringItem( index, gui_name )
     self.list_targets.SetStringItem( index, 1, str(probability) + "%" )
     self.__update_total_probability()
     self.__update_new_button()
     fsmevents.signal_fsm_change(self, fsmevents.ID_NewTarget)
コード例 #8
0
 def __find_action(self, sm, action_script, log):
     # Look for the action script in all the leaf nodes of the FSM
     state_paths = fsm.get_states( sm.getfullname() )
     for state_path in state_paths:
         state = pynebula.lookup( state_path )
         if state.isa('nleafstate'):
             action = state.getbehaviouralaction()
             if action.getactiontype() == 999:
                 action.rewindargs()
                 if action.getstringarg() == action_script.getname():
                     log.append( [
                         sm.getname(),
                         fsmstates.get_state_gui_name( state_path )
                         ] )
コード例 #9
0
ファイル: fsmtargets.py プロジェクト: xuebai5/TheZombieEngine
    def __update_choice_state(self):
        # Get current target state path
        transition = self.__get_transition()
        target_state_path = transition.gettargetstatebyindex(
            self.target_index).getfullname()

        # Fill the state choicer with all the states in the fsm available
        # for the target's transition and select the current target state
        self.choice_state.Clear()
        states_paths = get_free_targets(self.transition_path,
                                        target_state_path)
        for state_path in states_paths:
            gui_name = fsmstates.get_state_gui_name(state_path)
            index = self.choice_state.Append(gui_name)
            if state_path == target_state_path:
                self.choice_state.Select(index)
コード例 #10
0
ファイル: fsmtargets.py プロジェクト: xuebai5/TheZombieEngine
 def __update_choice_state(self):
     # Get current target state path
     transition = self.__get_transition()
     target_state_path = transition.gettargetstatebyindex(
         self.target_index ).getfullname()
     
     # Fill the state choicer with all the states in the fsm available
     # for the target's transition and select the current target state
     self.choice_state.Clear()
     states_paths = get_free_targets( self.transition_path,
         target_state_path )
     for state_path in states_paths:
         gui_name = fsmstates.get_state_gui_name( state_path )
         index = self.choice_state.Append( gui_name )
         if state_path == target_state_path:
             self.choice_state.Select( index )
コード例 #11
0
ファイル: fsmtargets.py プロジェクト: xuebai5/TheZombieEngine
    def set_transition(self, transition_path):
        self.transition_path = transition_path

        self.list_targets.DeleteAllItems()
        if transition_path != None:
            # Update the targets list
            transition = self.__get_transition()
            for i in range(transition.gettargetsnumber()):
                state = transition.gettargetstatebyindex(i)
                gui_name = fsmstates.get_state_gui_name(state.getfullname())
                probability = transition.gettargetprobabilitybyindex(i)
                self.list_targets.InsertStringItem(i, gui_name)
                self.list_targets.SetStringItem(i, 1, str(probability) + "%")

            # Update the total probability
            self.__update_total_probability()

        # Enable/disable this control
        self.Enable(self.transition_path != None)
        self.__update_new_button()
        self.button_delete.Enable(False)
コード例 #12
0
ファイル: fsmtargets.py プロジェクト: xuebai5/TheZombieEngine
 def set_transition(self, transition_path):
     self.transition_path = transition_path
     
     self.list_targets.DeleteAllItems()
     if transition_path != None:
         # Update the targets list
         transition = self.__get_transition()
         for i in range( transition.gettargetsnumber() ):
             state = transition.gettargetstatebyindex(i)
             gui_name = fsmstates.get_state_gui_name( state.getfullname() )
             probability = transition.gettargetprobabilitybyindex(i)
             self.list_targets.InsertStringItem( i, gui_name )
             self.list_targets.SetStringItem( i, 1, str(probability) + "%" )
         
         # Update the total probability
         self.__update_total_probability()
     
     # Enable/disable this control
     self.Enable( self.transition_path != None )
     self.__update_new_button()
     self.button_delete.Enable( False )
コード例 #13
0
def find_fsm_selector(selector_class):
    columns = ['FSM', 'State']
    rows = []
    
    # Look for the selector in all the FSMs
    fsm_paths = fsm.get_fsms()
    for fsm_path in fsm_paths:
        state_mc = pynebula.lookup( fsm_path )
        
        # Look for the selector in all the state nodes of the FSM
        state_paths = fsm.get_states( state_mc.getfullname() )
        for state_path in state_paths:
            state = pynebula.lookup( state_path )
            if state.isa('nnodestate'):
                selector = state.getfsmselector()
                if selector.isa( str(selector_class) ):
                    rows.append( [
                        state_mc.getname(),
                        fsmstates.get_state_gui_name( state_path )
                        ] )
    
    return (columns, rows)
コード例 #14
0
def find_behaviour_action(action_class):
    columns = ['FSM', 'State']
    rows = []
    
    # Look for the action in all the FSMs
    fsm_paths = fsm.get_fsms()
    for fsm_path in fsm_paths:
        state_mc = pynebula.lookup( fsm_path )
        
        # Look for the action in all the leaf nodes of the FSM
        state_paths = fsm.get_states( state_mc.getfullname() )
        for state_path in state_paths:
            state = pynebula.lookup( state_path )
            if state.isa('nleafstate'):
                action = state.getbehaviouralaction()
                if action.getactionclass() == action_class:
                    rows.append( [
                        state_mc.getname(),
                        fsmstates.get_state_gui_name( state_path )
                        ] )
    
    return (columns, rows)
コード例 #15
0
ファイル: fsmpreview.py プロジェクト: xuebai5/TheZombieEngine
    def __generate_dot_file(self):
        # Begin
        dot_file = open( self.dot_path, 'w' )
        dot_file.write( 'digraph G {\n' )
        
        # States
        fsm = pynebula.lookup( self.fsm_path )
        initial_state = fsm.getinitialstate()
        state = fsm.gethead()
        while state is not None:
            line = '    ' + state.getname()
            label = fsmstates.get_state_gui_name( state.getfullname() )
            line = line + ' [label="' + label + '"'
            line = line + ' , URL="state:' + state.getfullname() + '"'
            if state.isa('nnodestate'):
                line = line + ', style=dashed'
            elif state.isa('nendstate'):
                line = line + ', peripheries=2'
            else:
                line = line + ', style=solid'
            if state == initial_state:
                line = line + ', shape=box'
            line = line + '];\n'
            dot_file.write(line)
            
            # State transitions
            try:
                transition = pynebula.lookup( str(state.getfullname() +
                    "/transitions") ).gethead()
            except:
                transition = None
            while transition is not None:
                condition = transition.getcondition()
                for i in range( transition.gettargetsnumber() ):
                    line = '    ' + state.getname() + ' -> '
                    line = line + transition.gettargetstatebyindex(i).getname()
                    probability = transition.gettargetprobabilitybyindex(i)
                    label = fsmtransitions.get_transition_gui_name( transition.getfullname() ).split(' ',1)[1]
                    if probability != 100:
                        label = label + '\\n(' + str(probability) + '%)'
                    line = line + ' [label="' + label + '"'
                    line = line + ' URL="transition:' + transition.getfullname()
                    line = line + '/' + str(i) + '"'
                    if condition.isa('nscriptcondition'):
                        line = line + ', arrowhead=onormal'
                    if probability != 100:
                        line = line + ', style=dotted'
                    line = line + '];\n'
                    dot_file.write(line)
                transition = transition.getsucc()
            
            state = state.getsucc()
##        dot_file.write( '    B [label="Attack", style=dashed];\n' )
##        dot_file.write( '    A -> B [label="True", arrowhead=onormal];\n' )
##        dot_file.write( '    B -> A [label="Done"];\n' )
##        dot_file.write( '    \n' )
##        dot_file.write( '    C [label="Shoot", style=bold]\n' );
##        dot_file.write( '    D [label="End shooting", peripheries=2];\n' )
##        dot_file.write( '    C -> D [label="True", arrowhead=onormal];\n' )
        
        # End
        dot_file.write( '}\n' )
        dot_file.close()
コード例 #16
0
ファイル: fsmpreview.py プロジェクト: xuebai5/TheZombieEngine
    def __generate_dot_file(self):
        # Begin
        dot_file = open(self.dot_path, 'w')
        dot_file.write('digraph G {\n')

        # States
        fsm = pynebula.lookup(self.fsm_path)
        initial_state = fsm.getinitialstate()
        state = fsm.gethead()
        while state is not None:
            line = '    ' + state.getname()
            label = fsmstates.get_state_gui_name(state.getfullname())
            line = line + ' [label="' + label + '"'
            line = line + ' , URL="state:' + state.getfullname() + '"'
            if state.isa('nnodestate'):
                line = line + ', style=dashed'
            elif state.isa('nendstate'):
                line = line + ', peripheries=2'
            else:
                line = line + ', style=solid'
            if state == initial_state:
                line = line + ', shape=box'
            line = line + '];\n'
            dot_file.write(line)

            # State transitions
            try:
                transition = pynebula.lookup(
                    str(state.getfullname() + "/transitions")).gethead()
            except:
                transition = None
            while transition is not None:
                condition = transition.getcondition()
                for i in range(transition.gettargetsnumber()):
                    line = '    ' + state.getname() + ' -> '
                    line = line + transition.gettargetstatebyindex(i).getname()
                    probability = transition.gettargetprobabilitybyindex(i)
                    label = fsmtransitions.get_transition_gui_name(
                        transition.getfullname()).split(' ', 1)[1]
                    if probability != 100:
                        label = label + '\\n(' + str(probability) + '%)'
                    line = line + ' [label="' + label + '"'
                    line = line + ' URL="transition:' + transition.getfullname(
                    )
                    line = line + '/' + str(i) + '"'
                    if condition.isa('nscriptcondition'):
                        line = line + ', arrowhead=onormal'
                    if probability != 100:
                        line = line + ', style=dotted'
                    line = line + '];\n'
                    dot_file.write(line)
                transition = transition.getsucc()

            state = state.getsucc()
##        dot_file.write( '    B [label="Attack", style=dashed];\n' )
##        dot_file.write( '    A -> B [label="True", arrowhead=onormal];\n' )
##        dot_file.write( '    B -> A [label="Done"];\n' )
##        dot_file.write( '    \n' )
##        dot_file.write( '    C [label="Shoot", style=bold]\n' );
##        dot_file.write( '    D [label="End shooting", peripheries=2];\n' )
##        dot_file.write( '    C -> D [label="True", arrowhead=onormal];\n' )

# End
        dot_file.write('}\n')
        dot_file.close()