fn execute_systems_node(&mut self, instance_index: usize, node_id: usize) -> Option<BehaviorNodeConnector> {

        let mut connectors : Vec<BehaviorNodeConnector> = vec![];
        let mut connected_node_ids : Vec<usize> = vec![];
        let mut possibly_executed_connections : Vec<(BehaviorType, usize, BehaviorNodeConnector)> = vec![];

        let mut is_sequence = false;
        let mut rc : Option<BehaviorNodeConnector> = None;

        // Call the node and get the resulting BehaviorNodeConnector
        if let Some(system) = self.systems.get_mut(&self.instances[instance_index].systems_id) {
            if let Some(node) = system.data.nodes.get_mut(&node_id) {

                // Handle special nodes
                if node.behavior_type == BehaviorNodeType::BehaviorTree || node.behavior_type == BehaviorNodeType::Linear {
                    connectors.push(BehaviorNodeConnector::Bottom1);
                    connectors.push(BehaviorNodeConnector::Bottom2);
                    connectors.push(BehaviorNodeConnector::Bottom);
                } else
                if node.behavior_type == BehaviorNodeType::Sequence {
                    connectors.push(BehaviorNodeConnector::Bottom1);
                    connectors.push(BehaviorNodeConnector::Bottom2);
                    connectors.push(BehaviorNodeConnector::Bottom);
                    connectors.push(BehaviorNodeConnector::Bottom3);
                    connectors.push(BehaviorNodeConnector::Bottom4);                    is_sequence = true;
                } else {
                    if let Some(node_call) = self.nodes.get_mut(&node.behavior_type) {
                        let systems_id = self.instances[instance_index].systems_id.clone();
                        let connector = node_call(instance_index, (systems_id, node_id), self, BehaviorType::Systems);
                        rc = Some(connector);
                        connectors.push(connector);
                    } else {
                        connectors.push(BehaviorNodeConnector::Bottom);
                    }
                }
            }
        }

        // Search the connections to check if we can find an ongoing node connection
        for connector in connectors {
            if let Some(system) = self.systems.get_mut(&self.instances[instance_index].systems_id) {

                for c in &system.data.connections {
                    if c.0 == node_id && c.1 == connector {
                        connected_node_ids.push(c.2);
                        if is_sequence == false {
                            self.executed_connections.push((BehaviorType::Systems, c.0, c.1));
                        } else {
                            possibly_executed_connections.push((BehaviorType::Systems, c.0, c.1));
                        }
                    }
                }
            }
        }

        // And if yes execute it
        for (index, connected_node_id) in connected_node_ids.iter().enumerate() {

            // If this is a sequence, mark this connection as executed
            if is_sequence {
                self.executed_connections.push(possibly_executed_connections[index]);
            }

            if let Some(connector) = self.execute_systems_node(instance_index, *connected_node_id) {
                if is_sequence {
                    // Inside a sequence break out if the connector is not Success
                    if connector == BehaviorNodeConnector::Fail || connector == BehaviorNodeConnector::Right {
                        break;
                    }
                }
            }
        }
        rc
    }
/// Executes the given systems node and follows the connection chain
Executes the given systems node and follows the connection chain
Executes the given systems node and follows the connection chain
fn execute_systems_node(&mut self, instance_index: usize, node_id: usize) -> Option<BehaviorNodeConnector> {
        let mut connectors : Vec<BehaviorNodeConnector> = vec![];
        let mut connected_node_ids : Vec<usize> = vec![];
        let mut possibly_executed_connections : Vec<(BehaviorType, usize, BehaviorNodeConnector)> = vec![];
        let mut is_sequence = false;
        let mut rc : Option<BehaviorNodeConnector> = None;
        // Call the node and get the resulting BehaviorNodeConnector
        if let Some(system) = self.systems.get_mut(&self.instances[instance_index].systems_id) {
            if let Some(node) = system.data.nodes.get_mut(&node_id) {
                // Handle special nodes
                if node.behavior_type == BehaviorNodeType::BehaviorTree || node.behavior_type == BehaviorNodeType::Linear {
                    connectors.push(BehaviorNodeConnector::Bottom1);
                    connectors.push(BehaviorNodeConnector::Bottom2);
                    connectors.push(BehaviorNodeConnector::Bottom);
                } else
                if node.behavior_type == BehaviorNodeType::Sequence {
                    connectors.push(BehaviorNodeConnector::Bottom1);
                    connectors.push(BehaviorNodeConnector::Bottom2);
                    connectors.push(BehaviorNodeConnector::Bottom);
                    connectors.push(BehaviorNodeConnector::Bottom3);
                    connectors.push(BehaviorNodeConnector::Bottom4);                    is_sequence = true;
                } else {
                    if let Some(node_call) = self.nodes.get_mut(&node.behavior_type) {
                        let systems_id = self.instances[instance_index].systems_id.clone();
                        let connector = node_call(instance_index, (systems_id, node_id), self, BehaviorType::Systems);
                        rc = Some(connector);
                        connectors.push(connector);
                    } else {
                        connectors.push(BehaviorNodeConnector::Bottom);
                    }
                }
            }
        }
        // Search the connections to check if we can find an ongoing node connection
        for connector in connectors {
            if let Some(system) = self.systems.get_mut(&self.instances[instance_index].systems_id) {
                for c in &system.data.connections {
                    if c.0 == node_id && c.1 == connector {
                        connected_node_ids.push(c.2);
                        if is_sequence == false {
                            self.executed_connections.push((BehaviorType::Systems, c.0, c.1));
                        } else {
                            possibly_executed_connections.push((BehaviorType::Systems, c.0, c.1));
                        }
                    }
                }
            }
        }
        // And if yes execute it
        for (index, connected_node_id) in connected_node_ids.iter().enumerate() {
            // If this is a sequence, mark this connection as executed
            if is_sequence {
                self.executed_connections.push(possibly_executed_connections[index]);
            }
            if let Some(connector) = self.execute_systems_node(instance_index, *connected_node_id) {
                if is_sequence {
                    // Inside a sequence break out if the connector is not Success
                    if connector == BehaviorNodeConnector::Fail || connector == BehaviorNodeConnector::Right {
                        break;
                    }
                }
            }
        }
        rc
    }
fn execute_systems_node ( & mut self , instance_index : usize , node_id : usize ) -> Option < BehaviorNodeConnector > { let mut connectors : Vec < BehaviorNodeConnector > = vec ! [ ] ; let mut connected_node_ids : Vec < usize > = vec ! [ ] ; let mut possibly_executed_connections : Vec < ( BehaviorType , usize , BehaviorNodeConnector ) > = vec ! [ ] ; let mut is_sequence = false ; let mut rc : Option < BehaviorNodeConnector > = None ; // Call the node and get the resulting BehaviorNodeConnector if let Some ( system ) = self . systems . get_mut ( & self . instances [ instance_index ] . systems_id ) { if let Some ( node ) = system . data . nodes . get_mut ( & node_id ) { // Handle special nodes if node . behavior_type == BehaviorNodeType :: BehaviorTree || node . behavior_type == BehaviorNodeType :: Linear { connectors . push ( BehaviorNodeConnector :: Bottom1 ) ; connectors . push ( BehaviorNodeConnector :: Bottom2 ) ; connectors . push ( BehaviorNodeConnector :: Bottom ) ; } else if node . behavior_type == BehaviorNodeType :: Sequence { connectors . push ( BehaviorNodeConnector :: Bottom1 ) ; connectors . push ( BehaviorNodeConnector :: Bottom2 ) ; connectors . push ( BehaviorNodeConnector :: Bottom ) ; connectors . push ( BehaviorNodeConnector :: Bottom3 ) ; connectors . push ( BehaviorNodeConnector :: Bottom4 ) ; is_sequence = true ; } else { if let Some ( node_call ) = self . nodes . get_mut ( & node . behavior_type ) { let systems_id = self . instances [ instance_index ] . systems_id . clone ( ) ; let connector = node_call ( instance_index , ( systems_id , node_id ) , self , BehaviorType :: Systems ) ; rc = Some ( connector ) ; connectors . push ( connector ) ; } else { connectors . push ( BehaviorNodeConnector :: Bottom ) ; } } } } // Search the connections to check if we can find an ongoing node connection for connector in connectors { if let Some ( system ) = self . systems . get_mut ( & self . instances [ instance_index ] . systems_id ) { for c in & system . data . connections { if c . 0 == node_id && c . 1 == connector { connected_node_ids . push ( c . 2 ) ; if is_sequence == false { self . executed_connections . push ( ( BehaviorType :: Systems , c . 0 , c . 1 ) ) ; } else { possibly_executed_connections . push ( ( BehaviorType :: Systems , c . 0 , c . 1 ) ) ; } } } } } // And if yes execute it for ( index , connected_node_id ) in connected_node_ids . iter ( ) . enumerate ( ) { // If this is a sequence, mark this connection as executed if is_sequence { self . executed_connections . push ( possibly_executed_connections [ index ] ) ; } if let Some ( connector ) = self . execute_systems_node ( instance_index , * connected_node_id ) { if is_sequence { // Inside a sequence break out if the connector is not Success if connector == BehaviorNodeConnector :: Fail || connector == BehaviorNodeConnector :: Right { break ; } } } } rc }
Executes the given systems node and follows the connection chain
Executes the given systems node and follows the connection chain
&mut self
instance_index
usize
node_id
usize
&mut self
instance_index
usize
node_id
usize