/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public override void ParseTasks(Bullet bullet) { //set the number of times to repeat this action var actionNode = Node as ActionNode; Debug.Assert(null != actionNode); RepeatNumMax = actionNode.RepeatNum(this, bullet); //is this an actionref task? if (ENodeName.actionRef == Node.Name) { //add a sub task under this one for the referenced action ActionRefNode myActionRefNode = Node as ActionRefNode; //create the action task ActionTask actionTask = new ActionTask(myActionRefNode.ReferencedActionNode, this); //parse the children of the action node into the task actionTask.ParseTasks(bullet); //store the task ChildTasks.Add(actionTask); } //call the base class base.ParseTasks(bullet); }
/// <summary> /// Get the number of times this action should be repeated. /// </summary> /// <param name="myTask">the task to get the number of repeat times for</param> /// <returns>The number of times to repeat this node, as specified by a parent Repeat node.</returns> public int RepeatNum(ActionTask myTask, Bullet bullet) { if (null != ParentRepeatNode) { //Get the equation value of the repeat node return (int)ParentRepeatNode.GetChildValue(ENodeName.times, myTask, bullet); } else { //no repeat nodes, just repeat it once return 1; } }
/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public override void ParseTasks(Bullet bullet) { //is this an actionref task? if (ENodeName.actionRef == Node.Name) { //add a sub task under this one for the referenced action ActionRefNode myActionRefNode = Node as ActionRefNode; //create the action task ActionTask actionTask = new ActionTask(myActionRefNode.ReferencedActionNode, this); //parse the children of the action node into the task actionTask.ParseTasks(bullet); //store the task ChildTasks.Add(actionTask); } //call the base class base.ParseTasks(bullet); }
/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public virtual void ParseChildNode(BulletMLNode childNode, Bullet bullet) { Debug.Assert(null != childNode); Debug.Assert(null != bullet); //construct the correct type of node switch (childNode.Name) { case ENodeName.repeat: { //convert the node to an repeatnode RepeatNode myRepeatNode = childNode as RepeatNode; //create a placeholder bulletmltask for the repeat node RepeatTask repeatTask = new RepeatTask(myRepeatNode, this); //parse the child nodes into the repeat task repeatTask.ParseTasks(bullet); //store the task ChildTasks.Add(repeatTask); } break; case ENodeName.action: { //convert the node to an ActionNode ActionNode myActionNode = childNode as ActionNode; //create the action task ActionTask actionTask = new ActionTask(myActionNode, this); //parse the children of the action node into the task actionTask.ParseTasks(bullet); //store the task ChildTasks.Add(actionTask); } break; case ENodeName.actionRef: { //convert the node to an ActionNode ActionRefNode myActionNode = childNode as ActionRefNode; //create the action task ActionTask actionTask = new ActionTask(myActionNode, this); //add the params to the action task for (int i = 0; i < childNode.ChildNodes.Count; i++) { actionTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this, bullet)); } //parse the children of the action node into the task actionTask.ParseTasks(bullet); //store the task ChildTasks.Add(actionTask); } break; case ENodeName.changeSpeed: { ChildTasks.Add(new ChangeSpeedTask(childNode as ChangeSpeedNode, this)); } break; case ENodeName.changeDirection: { ChildTasks.Add(new ChangeDirectionTask(childNode as ChangeDirectionNode, this)); } break; case ENodeName.fire: { //convert the node to a fire node FireNode myFireNode = childNode as FireNode; //create the fire task FireTask fireTask = new FireTask(myFireNode, this); //parse the children of the fire node into the task fireTask.ParseTasks(bullet); //store the task ChildTasks.Add(fireTask); } break; case ENodeName.fireRef: { //convert the node to a fireref node FireRefNode myFireNode = childNode as FireRefNode; //create the fire task FireTask fireTask = new FireTask(myFireNode.ReferencedFireNode, this); //add the params to the fire task for (int i = 0; i < childNode.ChildNodes.Count; i++) { fireTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this, bullet)); } //parse the children of the action node into the task fireTask.ParseTasks(bullet); //store the task ChildTasks.Add(fireTask); } break; case ENodeName.wait: { ChildTasks.Add(new WaitTask(childNode as WaitNode, this)); } break; case ENodeName.vanish: { ChildTasks.Add(new VanishTask(childNode as VanishNode, this)); } break; case ENodeName.accel: { ChildTasks.Add(new AccelTask(childNode as AccelNode, this)); } break; } }