/// <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 Parse(BulletMLNode myNode, Bullet bullet) { Debug.Assert(null != myNode); Debug.Assert(null != bullet); foreach (BulletMLNode childNode in myNode.ChildNodes) { //construct the correct type of node switch (childNode.Name) { case ENodeName.repeat: { Parse(childNode, bullet); } break; case ENodeName.action: { int repeatNum = 1; //find how many times to repeat this action BulletMLNode RepeatNode = childNode.FindParentNode(ENodeName.repeat); if (null != RepeatNode) { repeatNum = (int)RepeatNode.GetChildValue(ENodeName.times, this); } BulletMLAction task = new BulletMLAction(repeatNum, myNode, this); ChildTasks.Add(task); task.Parse(childNode, bullet); } break; case ENodeName.actionRef: { //find the referenced node BulletMLNode refNode = myNode.GetRootNode().FindLabelNode(childNode.Label, ENodeName.action); //find how many times to repeat the referenced action int repeatNum = 1; BulletMLNode RepeatNode = myNode.FindParentNode(ENodeName.repeat); if (null != RepeatNode) { repeatNum = (int)RepeatNode.GetChildValue(ENodeName.times, this); } BulletMLAction task = new BulletMLAction(repeatNum, refNode, this); ChildTasks.Add(task); for (int i = 0; i < childNode.ChildNodes.Count; i++) { task.ParamList.Add(childNode.ChildNodes[i].GetValue(this)); } task.Parse(refNode, bullet); } break; case ENodeName.changeSpeed: { ChildTasks.Add(new BulletMLChangeSpeed(childNode, this)); } break; case ENodeName.changeDirection: { ChildTasks.Add(new BulletMLChangeDirection(childNode, this)); } break; case ENodeName.fire: { ChildTasks.Add(new BulletMLFire(childNode, this)); } break; case ENodeName.fireRef: { //find the node that was referenced BulletMLNode refNode = myNode.GetRootNode().FindLabelNode(childNode.Label, ENodeName.fire); BulletMLFire fire = new BulletMLFire(refNode, this); ChildTasks.Add(fire); for (int i = 0; i < childNode.ChildNodes.Count; i++) { fire.ParamList.Add(childNode.ChildNodes[i].GetValue(this)); } } break; case ENodeName.wait: { ChildTasks.Add(new BulletMLWait(childNode, this)); } break; case ENodeName.speed: { //speed nodes are special, just pull the value out and set up the bullet bullet.GetFireData().speedInit = true; bullet.Velocity = childNode.GetValue(this); } break; case ENodeName.direction: { ChildTasks.Add(new BulletMLSetDirection(childNode, this)); } break; case ENodeName.vanish: { ChildTasks.Add(new BulletMLVanish(childNode, this)); } break; case ENodeName.accel: { ChildTasks.Add(new BulletMLAccel(childNode, this)); } break; } } //After all the nodes are read in, initialize the node Init(); }