//
        /// <summary>
        /// We have a story node
        /// </summary>
        /// <param name="sNode">The story node we are editing</param>
        /// <param name="giver">The current giver</param>
        /// <param name="villian">The current villian</param>
        /// <param name="extra">The current extras</param>
        /// <param name="props">The current items</param>
        /// <param name="prevStoryNodes">The previous story nodes</param>
        /// <param name="triggers">The current triggers</param>
        /// <param name="module">The module we are using</param>
        public StoryNodeForm(StoryNode sNode, Actor giver, Actor villian, LinkedList<Actor> extra, LinkedList<Actor> props, LinkedList<StoryNode> prevStoryNodes, LinkedList<Actor> triggers, NWN2GameModule module)
        {
            InitializeComponent();
            storyNodeName.Text = sNode.Name;

            basicSetup(giver, villian, extra, props, prevStoryNodes, triggers, module);
            comboActor.SelectedItem = sNode.actor;

            if (comboActor.SelectedItem == null && comboActor.Items.Count > 0)
                {
                comboActor.SelectedIndex = 0;
                }

            comboTriggers.SelectedItem = trigger;

            // Look at this null comparison to see if it is correct
            if (comboTriggers.SelectedItem == null && comboTriggers.Items.Count > 0)
                {
                comboTriggers.SelectedIndex = 0;
                }

            // I add the data to the "What happens" field
            switch (sNode.happensEnum)
                {
                case EnumTypes.happens.Conv:
                    radioConvs.Checked = true;
                    break;

                case EnumTypes.happens.Conflict:
                    radioVillian.Checked = true;
                    break;

                case EnumTypes.happens.OpenDoor:
                    radioDoor.Checked = true;
                    break;

                case EnumTypes.happens.Trigger:
                    triggerRadio.Checked = true;
                    break;
                }

            /* I set options (radiobuttons and checkbuttons)
            These are independant of the above as the user may fiddle around
             */
            // Conv: I set the escort/explore options
            checkExplore.Checked = (sNode.convHappens == StoryNode.convType.Explore);
            checkEscort.Checked = (sNode.convHappens == StoryNode.convType.Escort);

            // Villian
            checkVillianTalk.Checked = sNode.villianTalk;
            checkVillianItem.Checked = (sNode.villianGotItem && sNode.actor.type == EnumTypes.actorType.Creature);

            //Door or placable:
            checkContainerContains.Checked = (sNode.villianGotItem && sNode.actor.type == EnumTypes.actorType.Placeable);

            // Trigger:
            radioFinishEscort.Checked = (sNode.triggerHappens == StoryNode.convType.Escort);
            radioFinishExplore.Checked = (sNode.triggerHappens == StoryNode.convType.Explore);
            triggerPanel.Enabled = (sNode.happensEnum == EnumTypes.happens.Trigger);

            // I add the data to the "Conversation Type" field

            #region Conversation Type
            switch (sNode.convEnum)
                {
                case EnumTypes.conv.QuestInfo:
                    radioQuestInfo.Checked = true;
                    break;

                case EnumTypes.conv.Single:
                    radioSingleStatement.Checked = true;
                    break;

                case EnumTypes.conv.None: break;
                }
            #endregion

            #region Items
            if ((sNode.giveItem != null) || (sNode.giveGold > 0))
                {
                comboGiveItem.SelectedItem = sNode.giveItem;
                giveItemNumber.Value = sNode.takeNumber;
                giveGold.Text = sNode.giveGold.ToString();
                checkGive.Checked = true;
                }

            if ((sNode.takeItem != null) || (sNode.takeGold > 0))
                {
                comboTakeItem.SelectedItem = sNode.takeItem;
                takeItemNumber.Value = sNode.takeNumber;
                takeGold.Text = sNode.takeGold.ToString();
                checkTake.Checked = true;
                }

            if (sNode.villianItem != null)
                {
                comboDropItem.SelectedItem = sNode.villianItem;
                }
            #endregion

            #region convesation
            greetBox.Text = sNode.greeting;
            acceptBox.Text = sNode.acceptence;
            actionBox.Text = sNode.action;
            rejectBox.Text = sNode.rejection;
            #endregion

            #region Prerequisite
            switch (sNode.preReq)
                {
                case EnumTypes.prereq.NoPrereq: radioNoPreReq.Checked = true;
                    break;

                case EnumTypes.prereq.SimplePrereq: radioSimpPreReq.Checked = true;
                    //        if(prevStoryNodes.Contains(sNode.preReq) {
                    comboPreRec.SelectedItem = sNode.preReqNode;
                    //      }
                    break;

                case EnumTypes.prereq.CastSpecificPrereq: radioCastSpecPreReq.Checked = true;
                    //  if(prevStoryNodes.Contains(sNode.preReq) {
                    comboPreRec.SelectedItem = sNode.preReqNode;
                    //  }
                    break;
                }
            #endregion

            // Journal field
            JournalBox.Text = sNode.journal;
            checkJournal.Checked = sNode.journalCheck;

            // EndPoint?
            checkEndPoint.Checked = sNode.endPoint;

            XP.Text = sNode.xp.ToString();
        }
        /// <summary>
        /// Gets all the information from the form and makes it into a story node
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void finish_Click(object sender, EventArgs e)
        {
            #region Initial Checks
            if (storyNodeName.Text == String.Empty)
                {
                report("You need to give the story node a name");
                storyNodeName.Focus();
                return;
                }
            if (comboActor.SelectedItem == null)
                {
                report("You need to select an actor");
                comboActor.Focus();
                return;
                }
            if ((radioSimpPreReq.Checked || radioCastSpecPreReq.Checked) && comboPreRec.SelectedItem == null)
                {
                report("You need to choose a story node or choose to have no prerequisite");

                return;
                }

            // if either the journalCheck is disabled or the Journalbox is non-empty we continue
            if (checkJournal.Checked && JournalBox.Text == String.Empty)
                {
                report("You need to write something for the Journal entry");
                JournalBox.Focus();
                return;
                }
            #endregion

            // I create the story node
            sNode = new StoryNode(storyNodeName.Text, (Actor)comboActor.SelectedItem, (Actor)comboTriggers.SelectedItem, module);

            #region whatHappens
            // I set happens
            if (radioConvs.Checked)
                {
                sNode.happensEnum = EnumTypes.happens.Conv;
                }
            else if (radioVillian.Checked)
                {
                sNode.happensEnum = EnumTypes.happens.Conflict;
                sNode.villianTalk = checkVillianTalk.Checked;
                }
            else if (radioDoor.Checked)
                {
                sNode.happensEnum = EnumTypes.happens.OpenDoor;
                sNode.containerContains = checkContainerContains.Checked && checkContainerContains.Enabled;
                }
            else if (triggerRadio.Checked)
                {
                sNode.happensEnum = EnumTypes.happens.Trigger;
                }
            #endregion

            #region convType
            // I set the convType
            if (radioConvs.Checked || (radioVillian.Checked && checkVillianTalk.Checked) || radioDoor.Checked)
                {
                if (radioQuestInfo.Checked)
                    {
                    sNode.convEnum = EnumTypes.conv.QuestInfo;
                    }
                else
                    {
                    sNode.convEnum = EnumTypes.conv.Single;
                    }
                }

            // I set the type of the convTypeEnum (whatever the player has to escort/explore)
            if (checkEscort.Checked)
                {
                sNode.convHappens = StoryNode.convType.Escort;
                }
            else if (checkExplore.Checked)
                {
                sNode.convHappens = StoryNode.convType.Explore;
                }

            // I set whether the finish trigger is escort or Explore
            if (radioFinishEscort.Checked)
                {
                sNode.triggerHappens = StoryNode.convType.Escort;
                }
            else if (radioFinishExplore.Checked)
                {
                sNode.triggerHappens = StoryNode.convType.Explore;

                }
            #endregion

            #region Items
            // The Items

            bool end = false;
            if (checkTake.Checked && checkTake.Enabled)
                {
                if (comboTakeItem.SelectedItem != null && comboTakeItem.SelectedText.ToLower() != "nothing")
                    {
                    sNode.itemTake = (Actor)comboTakeItem.SelectedItem;
                    sNode.takeNumber = (int)takeItemNumber.Value;
                    debug("Take item: " + sNode.itemGive.ToString() + ", number: " + sNode.giveNumber);
                    }
                try
                    {
                    sNode.takeGold = int.Parse(takeGold.Text);
                    }
                catch //(Exception ex)
                    {
                    end = true;
                    report("You can only input integers");
                    }
                }

            if (checkGive.Checked && checkGive.Enabled)
                {

                if (comboGiveItem.SelectedItem != null && comboTakeItem.SelectedText.ToLower() != "nothing")
                    {
                    sNode.itemGive = (Actor)comboGiveItem.SelectedItem;
                    sNode.giveNumber = (int)giveItemNumber.Value;
                    debug("Give item: " + sNode.itemGive.ToString() + ", number: " + sNode.giveNumber);
                    }
                try
                    {
                    sNode.giveGold = int.Parse(giveGold.Text);
                    }
                catch// (Exception ex)
                    {
                    end = true;
                    report("You can only input integers");
                    }
                }

            // The villian part
            if (
                //(villianItem.Checked || containerContains.Checked) &&
                //  villianItem.Enabled
                comboDropItem.Enabled && comboDropItem.SelectedItem != null && comboDropItem.Text.ToLower() != "nothing")
                {
                //           System.Windows.Forms.report("Got item: " + ((Actor)dropItemCombo.SelectedItem).ToString());
                sNode.villianItem = (Actor)comboDropItem.SelectedItem;
                sNode.villianGotItem = true;
                }
            #endregion Items

            #region Conversation
            // The conversation
            // For there to be an conversation, the conv options only needs to be enabled
            if (radioQuestInfo.Enabled)
                {
                sNode.greeting = greetBox.Text;

                if (radioQuestInfo.Checked)
                    {
                    sNode.acceptence = acceptBox.Text;
                    sNode.action = actionBox.Text;
                    sNode.rejection = rejectBox.Text;
                    }
                }

            if (triggers.Count > 0 && comboTriggers.Enabled == true)
                {
                trigger = (NWN2TriggerBlueprint)((Actor)comboTriggers.SelectedItem).blueprint;
                }
            #endregion

            #region PreRec
            sNode.preReq = EnumTypes.prereq.NoPrereq;
            if (comboPreRec.SelectedItem != null && !radioNoPreReq.Checked)
                {
                sNode.preReqNode = (StoryNode)comboPreRec.SelectedItem;

                if (radioSimpPreReq.Checked)
                    {
                    sNode.preReq = EnumTypes.prereq.SimplePrereq;
                    }
                else
                    {
                    sNode.preReq = EnumTypes.prereq.CastSpecificPrereq;
                    }
                }
            #endregion

            #region Journal and XP
            /* I add the journal text - if there is no text I will not add a
             * journal entry, nor will I use it as prerequiste
             */
            sNode.journal = JournalBox.Text;
            sNode.journalCheck = checkJournal.Checked;

            //.. and the xp

            try
                {
                sNode.xp = int.Parse(XP.Text);
                if (sNode.xp < 0)
                    {
                    report("XP must be given as a nonnegative value");
                    return;
                    }
                }
            catch
                {
                end = true;
                report("You can only input integers");
                return;
                }

            sNode.endPoint = checkEndPoint.Checked;

            if (!end)
                {
                DialogResult = DialogResult.OK;
                this.Close();
                }
            #endregion
        }
 /// <summary>
 /// Adds a story node that has the ending part of the trigger node that has just been added
 /// </summary>
 /// <param name="tempSNode">The story node to which we must add a  corosponding Trigger end node</param>
 private void addTriggerStoryNode(StoryNode tempSNode)
     {
     StoryNode newStoryNode = new StoryNode(tempSNode.Name + " end ", tempSNode.actor, tempSNode.trigger, module);
     newStoryNode.happensEnum = EnumTypes.happens.Trigger;
     newStoryNode.triggerHappens = tempSNode.convHappens;
     newStoryNode.preReqNode = tempSNode;
     newStoryNode.preReq = EnumTypes.prereq.SimplePrereq;
     if (tempSNode.convHappens == StoryNode.convType.Escort)
         {
         newStoryNode.greeting = "Thank you for Escorting me.";
         newStoryNode.journal = "I took him to his destination.";
         }
     else if (tempSNode.convHappens == StoryNode.convType.Explore)
         {
         newStoryNode.greeting = "XP granted for exploration";
         newStoryNode.journal = "I found the place I was looking for";
         }
     newStoryNode.endPoint = true;
     sNodeList.Items.Add(newStoryNode);
     }
 /// <summary>
 /// Static utility method to copy a story node
 /// </summary>
 /// <param name="sn">The story node to be copied</param>
 /// <returns>The copied story node</returns>
 public static StoryNode Copy(StoryNode sn)
 {
     return (StoryNode)sn.MemberwiseClone();
 }
 /// <summary>
 /// Should find all the previous elements in the Story Node list
 /// </summary>
 /// <param name="objs">The elements we are looking through</param>
 /// <param name="sNode">The node we are search until</param>
 private LinkedList<StoryNode> getPrev(ListBox.ObjectCollection objs, StoryNode sNode)
     {
     LinkedList<StoryNode> prevStoryNodes = new LinkedList<StoryNode>();
     StoryNode tempNode;
     foreach (object prevsNode in objs)
         {
         tempNode = (StoryNode)prevsNode;
         // If the StoryNode has either a journal entry or is an endPoint, then we skip it
         if (sNode != null && sNode == tempNode)
             break;
         if (!tempNode.journalCheck || tempNode.endPoint) continue;
         prevStoryNodes.AddLast(tempNode);
         }
     return prevStoryNodes;
     }