// Start is called before the first frame update void Start() { self = GetComponent <Kinematic>(); tank = GetComponent <Tank>(); mEffector = GetComponent <MovementEffector>(); dTree = new CheckShieldOnDecision(); ((Decision)dTree).testData = mEffector.ShieldStatus; ((CheckShieldOnDecision)dTree).trueNode = new ShotApproachingDecision(); // Shield is on. Is a shot approaching? (Should we leave it on?) ((ShotApproachingDecision)((CheckShieldOnDecision)dTree).trueNode).trueNode = new IsGunReadyDecision(); // A shot is coming, leave the shield alone. Can we return fire? ((IsGunReadyDecision)(((ShotApproachingDecision)((CheckShieldOnDecision)dTree).trueNode).trueNode)).trueNode = new FacingEnemyDecision(); // Are we facing the enemy? ((FacingEnemyDecision)(((IsGunReadyDecision)(((ShotApproachingDecision)((CheckShieldOnDecision)dTree).trueNode).trueNode)).trueNode)).trueNode = new ShootGunAction(); // Shoot! ((FacingEnemyDecision)(((IsGunReadyDecision)(((ShotApproachingDecision)((CheckShieldOnDecision)dTree).trueNode).trueNode)).trueNode)).falseNode = new Action(); // Not facing the enemy. Do nothing new. ((IsGunReadyDecision)(((ShotApproachingDecision)((CheckShieldOnDecision)dTree).trueNode).trueNode)).falseNode = new Action(); // We can't return fire. Do nothing new. ((ShotApproachingDecision)((CheckShieldOnDecision)dTree).trueNode).falseNode = new ShieldOffAction(); // Turn the shield off to conserve power. We don't need it right now. ((CheckShieldOnDecision)dTree).falseNode = new CanEnableShieldDecision(); // Shield is off. Can we have the shield on? ((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).trueNode = new ShotApproachingDecision(); // Is there a shot approaching the tank? SHOULD we turn it on? ((ShotApproachingDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).trueNode)).trueNode = new ShieldOnAction(); // Turn the shield on ((ShotApproachingDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).trueNode)).falseNode = new IsGunReadyDecision(); // Don't turn the shield on, but is the gun ready? (((IsGunReadyDecision)((ShotApproachingDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).trueNode)).falseNode)).trueNode = new FacingEnemyDecision(); // Are we facing the enemy? ((FacingEnemyDecision)(((IsGunReadyDecision)((ShotApproachingDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).trueNode)).falseNode)).trueNode).trueNode = new ShootGunAction(); // Shoot! ((FacingEnemyDecision)(((IsGunReadyDecision)((ShotApproachingDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).trueNode)).falseNode)).trueNode).falseNode = new Action(); // Do nothing new (((IsGunReadyDecision)((ShotApproachingDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).trueNode)).falseNode)).falseNode = new Action(); // Do nothing new ((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).falseNode = new IsGunReadyDecision(); // Can't turn shield on. But, can we shoot? ((IsGunReadyDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).falseNode)).trueNode = new FacingEnemyDecision(); // Are we facing the enemy? (((FacingEnemyDecision)(((IsGunReadyDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).falseNode)).trueNode))).trueNode = new ShootGunAction(); // Are we facing the enemy? (((FacingEnemyDecision)(((IsGunReadyDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).falseNode)).trueNode))).falseNode = new Action(); // Don't do anything new ((IsGunReadyDecision)(((CanEnableShieldDecision)((CheckShieldOnDecision)dTree).falseNode).falseNode)).falseNode = new Action(); // Do nothing new. List <State> states = new List <State>(); State fightState = new FightState(); fightState.GetTransitions().Add(new Transition()); states.Add(fightState); State fleeState = new FleeState(); fleeState.GetTransitions().Add(new Transition()); states.Add(fleeState); states[0].GetTransitions()[0].targetState = states[1]; states[1].GetTransitions()[0].targetState = states[0]; //states[0].GetTransitions()[0].bTriggered = true; sm = new StateMachine(this, states); }