Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public BulletMLTask(BulletMLNode node, BulletMLTask owner)
 {
     ChildTasks   = new List <BulletMLTask>();
     ParamList    = new List <float>();
     TaskFinished = false;
     this.Owner   = owner;
     this.Node    = node;
 }
Exemplo n.º 2
0
        /// <summary>
        /// This is the method that should be used to create tasks for this dude, since they have to sync up with firedata objects
        /// </summary>
        /// <returns>An empty task</returns>
        public BulletMLTask CreateTask()
        {
            BulletMLTask task = new BulletMLTask(null, null);

            _tasks.Add(task);
            _fireData.Add(new FireData());
            return(task);
        }
Exemplo n.º 3
0
        //TODO: sort all these shitty functions out

        public float GetChildValue(ENodeName name, BulletMLTask task)
        {
            foreach (BulletMLNode tree in ChildNodes)
            {
                if (tree.Name == name)
                {
                    return(tree.GetValue(task));
                }
            }
            return(0.0f);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This bullet is fired from another bullet, initialize it from the node that fired it
        /// </summary>
        /// <param name="subNode">Sub node that defines this bullet</param>
        public void Init(BulletMLNode subNode)
        {
            Debug.Assert(null != subNode);

            //clear everything out
            _activeTaskNum = 0;

            //Grab that top level node
            MyNode = subNode;

            //Either get the first task, or create a task for the node
            //If this dude is from a FireRef task, there will already be a plain task in there with all the required params
            BulletMLTask task = ((0 != _tasks.Count) ? _tasks[0] : CreateTask());

            //parse the nodes into the task list
            task.Parse(subNode, this);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLFire"/> class.
        /// </summary>
        /// <param name="node">Node.</param>
        /// <param name="owner">Owner.</param>
        public BulletMLFire(BulletMLNode node, BulletMLTask owner) : base(node, owner)
        {
            Debug.Assert(null != Node);
            Debug.Assert(null != Owner);

            //First try and get the nodes striaght from our node
            DirNode    = node.GetChild(ENodeName.direction);
            SpeedNode  = node.GetChild(ENodeName.speed);
            RefNode    = node.GetChild(ENodeName.bulletRef);
            BulletNode = node.GetChild(ENodeName.bullet);

            //ok fire nodes HAVE TO have either a ref or a bullet node
            Debug.Assert((null != RefNode) || (null != BulletNode));

            //what we gonna use to set the direction if we couldnt find a node?
            if (null == DirNode)
            {
                if (null != RefNode)
                {
                    //Get the direction from the reference node
                    DirNode = RefNode.GetChild(ENodeName.direction);
                }
                else if (BulletNode != null)
                {
                    //Set teh driection from teh bullet node
                    DirNode = BulletNode.GetChild(ENodeName.direction);
                }
            }

            //what we gonna use to set teh speed if we couldnt find a node?
            if (null == SpeedNode)
            {
                if (null != RefNode)
                {
                    //set the speed from teh refernce node
                    SpeedNode = RefNode.GetChild(ENodeName.speed);
                }
                else if (null != BulletNode)
                {
                    //set teh speed from the bullet node
                    SpeedNode = BulletNode.GetChild(ENodeName.speed);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize this bullet with a top level node
        /// </summary>
        /// <param name="rootNode">This is a top level node... find the first "top" node and use it to define this bullet</param>
        public void InitTop(BulletMLNode rootNode)
        {
            Debug.Assert(null != rootNode);

            //clear everything out
            _tasks.Clear();
            _fireData.Clear();
            _activeTaskNum = 0;

            //Grab that top level node
            MyNode = rootNode;

            //okay find the item labelled 'top'
            BulletMLNode topNode = rootNode.FindLabelNode("top", ENodeName.action);

            if (topNode != null)
            {
                //We found a top node, add a task for it, also add a firedata for the task
                BulletMLTask task = CreateTask();

                //parse the nodes into the task list
                task.Parse(topNode, this);
            }
            else
            {
                //ok there is no 'top' node, so that means we have a list of 'top#' nodes
                for (int i = 1; i < 10; i++)
                {
                    topNode = rootNode.FindLabelNode("top" + i, ENodeName.action);
                    if (topNode != null)
                    {
                        //found a top num node, add a task and firedata for it
                        BulletMLTask task = CreateTask();

                        //parse the nodes into the task list
                        task.Parse(topNode, this);
                    }
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public BulletMLChangeSpeed(BulletMLNode node, BulletMLTask owner) : base(node, owner)
 {
     Debug.Assert(null != Node);
     Debug.Assert(null != Owner);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLAction"/> class.
 /// </summary>
 /// <param name="repeatNumMax">Repeat number max.</param>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public BulletMLAction(int repeatNumMax, BulletMLNode node, BulletMLTask owner) : base(node, owner)
 {
     Debug.Assert(null != Node);
     Debug.Assert(null != Owner);
     this.RepeatNumMax = repeatNumMax;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public BulletMLWait(BulletMLNode node, BulletMLTask owner) : base(node, owner)
 {
     Debug.Assert(null != Node);
     Debug.Assert(null != Owner);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Gets the value of this node for a specific instance of a task.
 /// </summary>
 /// <returns>The value.</returns>
 /// <param name="task">Task.</param>
 public float GetValue(BulletMLTask task)
 {
     //send to the equation for an answer
     return(NodeEquation.Solve(task.GetParamValue));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public BulletMLSetDirection(BulletMLNode node, BulletMLTask owner) : base(node, owner)
 {
     Debug.Assert(null != Node);
     Debug.Assert(null != Owner);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Run this task and all subtasks against a bullet
        /// This is called once a frame during runtime.
        /// </summary>
        /// <returns>ERunStatus: whether this task is done, paused, or still running</returns>
        /// <param name="bullet">The bullet to update this task against.</param>
        public override ERunStatus Run(Bullet bullet)
        {
            //Find which direction to shoot the new bullet
            if (DirNode != null)
            {
                //get the direction continade in the node
                float newBulletDirection = (int)DirNode.GetValue(this) * (float)Math.PI / (float)180;
                switch (DirNode.NodeType)
                {
                case ENodeType.sequence:
                {
                    bullet.GetFireData().srcDir += newBulletDirection;
                }
                break;

                case ENodeType.absolute:
                {
                    bullet.GetFireData().srcDir = newBulletDirection;
                }
                break;

                case ENodeType.relative:
                {
                    bullet.GetFireData().srcDir = newBulletDirection + bullet.Direction;
                }
                break;

                default:
                {
                    bullet.GetFireData().srcDir = newBulletDirection + bullet.GetAimDir();
                }
                break;
                }
            }
            else
            {
                //otherwise if no direction node, aim the bullet at the bad guy
                bullet.GetFireData().srcDir = bullet.GetAimDir();
            }

            //Create the new bullet
            Bullet newBullet = bullet.MyBulletManager.CreateBullet();

            if (newBullet == null)
            {
                //wtf did you do???
                TaskFinished = true;
                return(ERunStatus.End);
            }

            //initialize the bullet from a reference node, or our bullet node
            if (RefNode != null)
            {
                //Add an empty task to the bullet and populate it with all the params
                BulletMLTask bulletBlankTask = newBullet.CreateTask();

                //Add all the params to the new task we just added to that bullet
                for (int i = 0; i < RefNode.ChildNodes.Count; i++)
                {
                    bulletBlankTask.ParamList.Add(RefNode.ChildNodes[i].GetValue(this));
                }

                //init the bullet now that all our stuff is prepopulated
                BulletMLNode subNode = bullet.MyNode.GetRootNode().FindLabelNode(RefNode.Label, ENodeName.bullet);
                newBullet.Init(subNode);
            }
            else
            {
                //if there is no ref node, there has to be  bullet node
                newBullet.Init(BulletNode);
            }

            //set the location of the new bullet
            newBullet.X = bullet.X;
            newBullet.Y = bullet.Y;

            //set the owner of the new bullet to this dude
            newBullet._tasks[0].Owner = this;

            //set the direction of the new bullet
            newBullet.Direction = bullet.GetFireData().srcDir;

            //Has the speed for new bullets been set in the source bullet yet?
            if (!bullet.GetFireData().speedInit&& newBullet.GetFireData().speedInit)
            {
                bullet.GetFireData().srcSpeed  = newBullet.Velocity;
                bullet.GetFireData().speedInit = true;
            }
            else
            {
                //find the speed for new bullets and store it in the source bullet
                if (SpeedNode != null)
                {
                    //Get the speed from a speed node
                    float newBulletSpeed = SpeedNode.GetValue(this);
                    if (SpeedNode.NodeType == ENodeType.sequence || SpeedNode.NodeType == ENodeType.relative)
                    {
                        bullet.GetFireData().srcSpeed += newBulletSpeed;
                    }
                    else
                    {
                        bullet.GetFireData().srcSpeed = newBulletSpeed;
                    }
                }
                else
                {
                    if (!newBullet.GetFireData().speedInit)
                    {
                        bullet.GetFireData().srcSpeed = 1;
                    }
                    else
                    {
                        bullet.GetFireData().srcSpeed = newBullet.Velocity;
                    }
                }
            }

            newBullet.GetFireData().speedInit = false;
            newBullet.Velocity = bullet.GetFireData().srcSpeed;

            TaskFinished = true;
            return(ERunStatus.End);
        }