Пример #1
0
 private void AddLookupWord(Keyword keyword)
 {
     if (!_lookupTable.ContainsKey(keyword.Command.ToLower()))
     {
         _lookupTable.Add(keyword.Command.ToLower(), keyword);
     }
 }
Пример #2
0
 private void RemoveLookupWord(Keyword keyword)
 {
     if (_lookupTable.ContainsKey(keyword.Command.ToLower()))
     {
         _lookupTable.Remove(keyword.Command);
     }
 }
Пример #3
0
        private static Keyword GetActivateAction()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "activateAction";
            keyword.FriendlyName = "Action Activate";
            keyword.HelpText = "Used to activate an action.";

            keyword.Inputs.Add(new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated."));

            return keyword;
        }
Пример #4
0
        private static Keyword GetActionTrue()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "if_action_true";
            keyword.FriendlyName = "Action Complete";
            keyword.HelpText = "Used for determining if a given action has been completed.";
            keyword.AllowConditional = true;

            KeywordInput action = new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated.");
            action.AllowableActions.Add(2);
            action.AllowableActions.Add(4);
            action.AllowableActions.Add(6);
            action.AllowableActions.Add(8);
            action.AllowableActions.Add(19);
            action.AllowableActions.Add(22);
            keyword.Inputs.Add(action);

            return keyword;
        }
Пример #5
0
        private static Keyword GetActionTrue()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "if_action_true";
            keyword.FriendlyName = "Action Complete";
            keyword.HelpText = "Used for determining if a given action has been completed.";
            keyword.AllowConditional = true;

            KeywordInput action = new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated.");
            action.AllowableActions.Add(2);
            action.AllowableActions.Add(4);
            action.AllowableActions.Add(6);
            action.AllowableActions.Add(8);
            action.AllowableActions.Add(19);
            action.AllowableActions.Add(22);
            //add some that are missing -crapshoot
            action.AllowableActions.Add(33); //expire
            action.AllowableActions.Add(34); //explode
            //this technically can be used with any action because it just checks goalnum
            keyword.Inputs.Add(action);

            return keyword;
        }
Пример #6
0
 public KeywordCompletionData(Keyword keyword)
 {
     _keyword = keyword;
 }
Пример #7
0
        public void SetupDataProvider(string fileName, ICSharpCode.TextEditor.TextArea textArea)
        {
            _textArea = textArea;
            _document = textArea.Document;
            _keywords = KeywordFactory.GetKeywords();

            //TODO: just put these keywords in the factory and add a flag for "IsRequired" or something.
            //      it may just require a KeywordType (Header, Action, etc). This needs cleaned up
            //      in the code completion data provider as well.

            // the keyword factory just has the non-required words
            Keyword sightDist = new Keyword("bot_SightDist", "", "", false);
            sightDist.Inputs.Add(new KeywordInput(KeywordInputType.Action, "Sight Distance", "How far the highest skill bot can see on this map. 1500 is good for non-foggy maps, 700 is good for foggy maps."));
            _keywords.Add(sightDist);

            _keywords.Add(new Keyword("spawnflag_is_priority", "",  "Whether or no bots focus on spawnflags.", false));
            _keywords.Add(new Keyword("cmdpost_is_priority", "",  "Whether or not command posts critical on this map.", false));
            _keywords.Add(new Keyword("construct_is_priority", "",  "Whether or not engineers focus more on constructibles.", false));
            _keywords.Add(new Keyword("map_has_vehicle", "",  "Type of vehicle 0 = none, 1 = tank, 2 = train", false));
            _keywords.Add(new Keyword("vehicle_entity_number", "",  "The entity number of the vehicle.", false));
            _keywords.Add(new Keyword("vehicle_team_owner", "",  "The owner of the vehicle.", false));

            LineSegment line = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);

            if (line != null)
            {
                TextWord first = GetWord(line, 1);

                if (first != null)
                {
                    Keyword keyword = _keywords.GetWord(first.Word);

                    if (keyword != null)
                    {
                        if (keyword.Inputs.Count > 0)
                        {
                            for (int x = 0; x < keyword.Inputs.Count; x++)
                            {
                                TextWord param = GetWord(line, x + 2);

                                if (param == null)
                                {
                                    KeywordInput inputParam = (KeywordInput)keyword.Inputs[x];

                                    if (inputParam.InputType != KeywordInputType.PredefinedList)
                                    {
                                        _insightKeywords.Add(new Keyword(inputParam.Label, inputParam.Label, inputParam.HelpText, false));
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #8
0
        private static Keyword GetIfConstructBuiltTrue()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "if_construct_built_true";
            keyword.FriendlyName = "If Constructible Is Built";
            keyword.HelpText = "Used for determining if an has been constructed. Associate a construct major or minor action with this command.";
            keyword.AllowConditional = true;

            KeywordInput action = new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated.");
            action.AllowableActions.Add(19);
            action.AllowableActions.Add(2);
            keyword.Inputs.Add(action);

            return keyword;
        }
Пример #9
0
 public void CopyTo(Keyword[] array, int index)
 {
     base.InnerList.CopyTo(array, index);
 }
Пример #10
0
 public void Insert(int index, Keyword keyword)
 {
     AddLookupWord(keyword);
     base.InnerList.Insert(index, keyword);
 }
Пример #11
0
        //crapshoot: openNodeGrpToTeam
        private static Keyword GetOpenNodeGrpToTeam()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "openNodeGrpToTeam";
            keyword.FriendlyName = "Open Node Group";
            keyword.HelpText = "Used to open a group of nodes to a team";

            keyword.Inputs.Add(new KeywordInput(KeywordInputType.Group, "Node Group", "The Group ID of nodes to open."));

            KeywordInput input = new KeywordInput(KeywordInputType.PredefinedList, "Team", "The Team to open the nodes for.");
            input.AllowableValues.Add("axis");
            input.AllowableValues.Add("allies");
            keyword.Inputs.Add(input);

            return keyword;
        }
Пример #12
0
 public int Add(Keyword keyword)
 {
     AddLookupWord(keyword);
     return base.InnerList.Add(keyword);
 }
Пример #13
0
        //crapshoot: Kill_Action
        private static Keyword GetKillAction()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "kill_action";
            keyword.FriendlyName = "Kill Action";
            keyword.HelpText = "Set action types to -1";

            keyword.Inputs.Add(new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated."));

            return keyword;
        }
Пример #14
0
        private static Keyword GetNodeDisconnect()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "node_disconnect";
            keyword.FriendlyName = "Node Disconnect";
            keyword.HelpText = "Used to disconnect nodes";

            keyword.Inputs.Add(new KeywordInput(KeywordInputType.Node, "Node ID 1", "The ID of the first node to disconnect."));
            keyword.Inputs.Add(new KeywordInput(KeywordInputType.Node, "Node ID 2", "The ID of the second node to discconnect."));

            KeywordInput input = new KeywordInput(KeywordInputType.PredefinedList, "Two Way Disconnect", "Whether or not this is a two way connection.");
            input.AllowableValues.Add("true");
            input.AllowableValues.Add("false");
            keyword.Inputs.Add(input);
            return keyword;
        }
Пример #15
0
        private static Keyword GetIfObjHomeTrue()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "if_obj_home_true";
            keyword.FriendlyName = "If Objective Is Home";
            keyword.HelpText = "Used for determining if an objective is in place. The action associated with this Keyword is typically a 'Steal' action for documents.";
            keyword.AllowConditional = true;

            KeywordInput action = new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated.");
            action.AllowableActions.Add(8);

            keyword.Inputs.Add(action);

            return keyword;
        }
Пример #16
0
        private static Keyword GetIfObjCaptured()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "if_obj_captured";
            keyword.FriendlyName = "If An Objective Captured";
            keyword.HelpText = "Used for determining if an objective has been captured. Associate the action that represents the objective.";
            keyword.AllowConditional = true;

            KeywordInput action = new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated.");
            action.AllowableActions.Add(8);
            keyword.Inputs.Add(action);

            return keyword;
        }
Пример #17
0
        private static Keyword GetIfFlagOwnerAxis()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "if_fda_owner_axis";
            keyword.FriendlyName = "If Axis Have Flag";
            keyword.HelpText = "Used for determining if the Axis have the flag. Associate a 'Spawn Flag' action with this command.";
            keyword.AllowConditional = true;

            KeywordInput action = new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated.");
            action.AllowableActions.Add(6);

            keyword.Inputs.Add(action);

            return keyword;
        }
Пример #18
0
        public ArrayList Validate(TextEditorControl editor, NavigationReader reader)
        {
            bool      isValid         = true;
            bool      inActionBracket = false;
            bool      actionsDefined  = false;
            IDocument document        = editor.Document;
            Hashtable required        = GetHeaderKeywords();
            Hashtable keywords        = GetKeywords();

            ArrayList messages = new ArrayList();

            if (reader == null)
            {
                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                msg.IsError = false;
                msg.Message = "Script validation will be more complete if you open a navigation file.";
                messages.Add(msg);
            }

            for (int x = 0; x < document.LineSegmentCollection.Count; x++)
            {
                LineSegment segment = (LineSegment)document.LineSegmentCollection[x];

                TextWord word = GetWord(segment, 1);

                if (word != null)
                {
                    if (required.ContainsKey(word.Word.ToLower()))
                    {
                        if (actionsDefined)
                        {
                            isValid = false;

                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                            msg.IsError    = true;
                            msg.LineNumber = x + 1;
                            msg.Message    = "Header parameter " + word.Word + " must be defined before actions.";
                            msg.ErrorWord  = word;
                            messages.Add(msg);
                        }

                        required.Remove(word.Word.ToLower());
                        TextWord val = GetWord(segment, 2);
                        TextWord bogusRequiredParam = GetWord(segment, 3);

                        if (val == null)
                        {
                            isValid = false;

                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                            msg.IsError    = true;
                            msg.LineNumber = x + 1;
                            msg.Message    = word.Word + " does not have a value defined.";
                            msg.ErrorWord  = word;
                            messages.Add(msg);
                        }
                        else
                        {
                            if (bogusRequiredParam != null)
                            {
                                isValid = false;

                                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                msg.IsError    = true;
                                msg.LineNumber = x + 1;
                                msg.Message    = word.Word + " has too many parameters defined.";
                                msg.ErrorWord  = word;
                                messages.Add(msg);
                            }

                            int param = GetWordInt(val);

                            if (param == Int32.MinValue)
                            {
                                isValid = false;

                                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                msg.IsError    = true;
                                msg.LineNumber = x + 1;
                                msg.Message    = word.Word + " has a non-numeric value defined.";
                                msg.ErrorWord  = word;
                                messages.Add(msg);
                            }
                            else
                            {
                                switch (word.Word.ToLower())
                                {
                                case "vehicle_entity_number":
                                case "bot_sightdist":
                                    if (param <= 0)
                                    {
                                        isValid = false;

                                        AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                        msg.IsError    = true;
                                        msg.Message    = word.Word + " should be greater than zero.";
                                        msg.LineNumber = x + 1;
                                        msg.ErrorWord  = word;
                                        messages.Add(msg);
                                    }
                                    break;

                                case "spawnflag_is_priority":
                                case "cmdpost_is_priority":
                                case "construct_is_priority":
                                    if (param != 0 && param != 1)
                                    {
                                        isValid = false;

                                        AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                        msg.IsError    = true;
                                        msg.Message    = word.Word + " should be 0 = false, 1 = true";
                                        msg.LineNumber = x + 1;
                                        msg.ErrorWord  = word;
                                        messages.Add(msg);
                                    }
                                    break;

                                case "map_has_vehicle":
                                    if (param != 0 && param != 1 && param != 2)
                                    {
                                        isValid = false;

                                        AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                        msg.IsError    = true;
                                        msg.Message    = word.Word + " should be 0 = none, 1 = tank, 2 = train";
                                        msg.LineNumber = x + 1;
                                        msg.ErrorWord  = word;
                                        messages.Add(msg);
                                    }
                                    else if (param == 0)
                                    {
                                        // not required if no vehicle
                                        required.Remove("vehicle_entity_number");
                                        required.Remove("vehicle_team_owner");
                                    }
                                    break;

                                case "vehicle_team_owner":
                                    if (param != 1 && param != 2)
                                    {
                                        isValid = false;

                                        AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                        msg.IsError    = true;
                                        msg.Message    = word.Word + " 1 = axis, 2 = allies";
                                        msg.LineNumber = x + 1;
                                        msg.ErrorWord  = word;
                                        messages.Add(msg);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    else if (keywords.ContainsKey(word.Word.ToLower()))
                    {
                        if (!inActionBracket)
                        {
                            isValid = false;

                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                            msg.IsError    = true;
                            msg.Message    = word.Word + " can only be defined inside an action.";
                            msg.LineNumber = x + 1;
                            msg.ErrorWord  = word;
                            messages.Add(msg);
                        }
                        else
                        {
                            Keyword keyword = (Keyword)keywords[word.Word.ToLower()];

                            int inputParamWord = 2;                             // second word is first input param

                            foreach (KeywordInput input in keyword.Inputs)
                            {
                                TextWord inputParam = GetWord(segment, inputParamWord);

                                if (inputParam == null)
                                {
                                    isValid = false;

                                    AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                    msg.IsError    = true;
                                    msg.Message    = word.Word + " expects an " + input.Label + " parameter. See script help for more information.";
                                    msg.LineNumber = x + 1;
                                    msg.ErrorWord  = word;
                                    messages.Add(msg);
                                }
                                else
                                {
                                    // validate based on input type :)
                                    switch (input.InputType)
                                    {
                                    case KeywordInputType.Integer:
                                        int inputInteger = GetWordInt(inputParam);

                                        if (inputInteger < 0)
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = word.Word + " has an invalid " + input.Label + " value. See script help for more information.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        break;

                                    case KeywordInputType.Action:
                                        int inputActionID = GetWordInt(inputParam);

                                        if (inputActionID < 0)
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = word.Word + " has an invalid " + input.Label + " value. See script help for more information.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        else
                                        {
                                            if (reader != null)
                                            {
                                                if (inputActionID > reader.Actions.Count - 1)
                                                {
                                                    isValid = false;

                                                    AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                                    msg.IsError    = true;
                                                    msg.Message    = word.Word + " has an " + input.Label + " value that is not in the opened navigation file.";
                                                    msg.LineNumber = x + 1;
                                                    msg.ErrorWord  = word;
                                                    messages.Add(msg);
                                                }
                                                else
                                                {
                                                    if (input.AllowableActions.Count > 0)
                                                    {
                                                        Action action = (Action)reader.Actions[inputActionID];

                                                        bool actionIsValid = false;

                                                        foreach (int validActionType in input.AllowableActions)
                                                        {
                                                            if (validActionType == action.AllyAction ||
                                                                validActionType == action.AxisAction)
                                                            {
                                                                actionIsValid = true;
                                                                break;
                                                            }
                                                        }

                                                        if (!actionIsValid)
                                                        {
                                                            isValid = false;

                                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                                            msg.IsError    = true;
                                                            msg.Message    = word.Word + " has an " + input.Label + " value that isn't valid. Verify the correct Allies and/or Axis action.";
                                                            msg.LineNumber = x + 1;
                                                            msg.ErrorWord  = word;
                                                            messages.Add(msg);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        break;

                                    case KeywordInputType.Boolean:
                                        if (inputParam.Word != "true" && inputParam.Word != "false")
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = word.Word + " " + input.Label + " should be either 'true' or 'false'.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        break;

                                    case KeywordInputType.Flag:
                                        int inputFlag = GetWordInt(inputParam);

                                        if (inputFlag < 0)
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = word.Word + " has an invalid " + input.Label + " value. Flags must be numeric and greater than or equal to zero.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        break;

                                    case KeywordInputType.Goal:
                                        int inputGoal = GetWordInt(inputParam);

                                        if (inputGoal < 0)
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = word.Word + " has an invalid " + input.Label + " value. Goals must be numeric and greater than or equal to zero.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        break;

                                    case KeywordInputType.Group:
                                        int inputGroup = GetWordInt(inputParam);

                                        if (inputGroup < 0)
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = word.Word + " has an invalid " + input.Label + " value. Groups must be numeric and greater than or equal to zero.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        break;

                                    case KeywordInputType.Node:
                                        int inputNode = GetWordInt(inputParam);

                                        if (inputNode < 0)
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = word.Word + " has an invalid " + input.Label + " value. Nodes must be numeric and greater than or equal to zero.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        else
                                        {
                                            if (reader != null)
                                            {
                                                if (inputNode > reader.Nodes.Count - 1)
                                                {
                                                    isValid = false;

                                                    AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                                    msg.IsError    = true;
                                                    msg.Message    = word.Word + " has an invalid " + input.Label + " value. The node defined does not exist in opened navigation file.";
                                                    msg.LineNumber = x + 1;
                                                    msg.ErrorWord  = word;
                                                    messages.Add(msg);
                                                }
                                            }
                                        }
                                        break;

                                    case KeywordInputType.PredefinedList:
                                        bool isAllowedValue = false;

                                        foreach (string allowed in input.AllowableValues)
                                        {
                                            if (allowed.ToLower() == inputParam.Word.ToLower())
                                            {
                                                isAllowedValue = true;
                                                break;
                                            }
                                        }

                                        if (!isAllowedValue)
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = inputParam.Word + " is not an allowed parameter for " + word.Word + ". See script help for more information.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        break;
                                    }
                                }

                                inputParamWord++;
                            }

                            TextWord bogusKeywordParam = GetWord(segment, inputParamWord);

                            if (bogusKeywordParam != null)
                            {
                                if (bogusKeywordParam.Word.ToLower() != "and" &&
                                    bogusKeywordParam.Word.ToLower() != "or")
                                {
                                    isValid = false;

                                    AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                    msg.IsError    = true;
                                    msg.Message    = word.Word + " has too many parameters defined. See script help for more information.";
                                    msg.LineNumber = x + 1;
                                    msg.ErrorWord  = word;
                                    messages.Add(msg);
                                }
                                else
                                {
                                    if (!keyword.AllowConditional)
                                    {
                                        isValid = false;

                                        AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                        msg.IsError    = true;
                                        msg.Message    = keyword.Command + " does not allow conditional statements.";
                                        msg.LineNumber = x + 1;
                                        msg.ErrorWord  = word;
                                        messages.Add(msg);
                                    }
                                    else
                                    {
                                        inputParamWord++;

                                        TextWord conditionalWord = GetWord(segment, inputParamWord);

                                        if (conditionalWord != null)
                                        {
                                            Keyword conditionalKeyword = keywords[conditionalWord.Word.ToLower()]
                                                                         as Keyword;

                                            if (conditionalKeyword == null)
                                            {
                                                isValid = false;

                                                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                                msg.IsError    = true;
                                                msg.Message    = keyword.Command + " conditional statement requires additional command.";
                                                msg.LineNumber = x + 1;
                                                msg.ErrorWord  = word;
                                                messages.Add(msg);
                                            }
                                            else
                                            {
                                                if (!conditionalKeyword.AllowConditional)
                                                {
                                                    isValid = false;

                                                    AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                                    msg.IsError    = true;
                                                    msg.Message    = conditionalKeyword.Command + " is not a valid conditional statement.";
                                                    msg.LineNumber = x + 1;
                                                    msg.ErrorWord  = word;
                                                    messages.Add(msg);
                                                }
                                                else
                                                {
                                                    // TODO: validate the params
                                                }
                                            }
                                        }
                                        else
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = keyword.Command + " conditional statement requires additional command.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (word.Word.ToLower() == "action")
                    {
                        actionsDefined = true;
                        if (inActionBracket)
                        {
                            isValid = false;

                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                            msg.IsError    = true;
                            msg.Message    = "Actions cannot be defined inside of other actions.";
                            msg.LineNumber = x + 1;
                            msg.ErrorWord  = word;
                            messages.Add(msg);
                        }
                        else
                        {
                            // validate int for second word
                            TextWord actionParam      = GetWord(segment, 2);
                            TextWord bogusActionParam = GetWord(segment, 3);

                            if (bogusActionParam != null)
                            {
                                isValid = false;

                                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                msg.IsError    = true;
                                msg.Message    = "Action has too many parameters defined.";
                                msg.LineNumber = x + 1;
                                msg.ErrorWord  = word;
                                messages.Add(msg);
                            }

                            if (actionParam == null)
                            {
                                isValid = false;

                                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                msg.IsError    = true;
                                msg.Message    = "Action does not have an ID";
                                msg.LineNumber = x + 1;
                                msg.ErrorWord  = word;
                                messages.Add(msg);
                            }
                            else
                            {
                                int actionNumber = GetWordInt(actionParam);

                                if (actionNumber < 0)
                                {
                                    isValid = false;

                                    AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                    msg.IsError    = true;
                                    msg.Message    = "Action has an invalid value.";
                                    msg.LineNumber = x + 1;
                                    msg.ErrorWord  = word;
                                    messages.Add(msg);
                                }
                                else
                                {
                                    // if reader avail, validate action exists and that it
                                    // is a scriptable action
                                    if (reader != null)
                                    {
                                        if (actionNumber > reader.Actions.Count - 1)
                                        {
                                            isValid = false;

                                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                            msg.IsError    = true;
                                            msg.Message    = "Action ID " + actionNumber + " does not exist in opened navigation file.";
                                            msg.LineNumber = x + 1;
                                            msg.ErrorWord  = word;
                                            messages.Add(msg);
                                        }
                                        else
                                        {
                                            Action action = (Action)reader.Actions[actionNumber];

                                            if (action.AllyAction != 4 && action.AxisAction != 4 &&
                                                action.AllyAction != 8 && action.AxisAction != 8 &&
                                                action.AllyAction != 19 && action.AxisAction != 19 &&
                                                action.AllyAction != 2 && action.AxisAction != 2 &&
                                                action.AllyAction != 22 && action.AxisAction != 22 &&
                                                action.AllyAction != 6 && action.AxisAction != 6)
                                            {
                                                isValid = false;

                                                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                                                msg.IsError    = true;
                                                msg.Message    = "Action ID " + actionNumber + " is not a scriptable action.";
                                                msg.LineNumber = x + 1;
                                                msg.ErrorWord  = word;
                                                messages.Add(msg);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (word.Word == "{")
                    {
                        inActionBracket = true;
                    }
                    else if (word.Word == "}")
                    {
                        inActionBracket = false;
                    }
                    else
                    {
                        if (!word.Word.StartsWith("#") && !word.Word.StartsWith("//"))
                        {
                            isValid = false;

                            AIScriptValidationMessage msg = new AIScriptValidationMessage();
                            msg.IsError    = true;
                            msg.Message    = "Unknown keyword defined [" + word.Word + "]";
                            msg.LineNumber = x + 1;
                            msg.ErrorWord  = word;
                            messages.Add(msg);
                        }
                    }
                }
            }

            foreach (string key in required.Keys)
            {
                isValid = false;

                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                msg.IsError = true;
                msg.Message = key + " is not defined.";
                messages.Add(msg);
            }

            if (isValid)
            {
                AIScriptValidationMessage msg = new AIScriptValidationMessage();
                msg.IsError = false;
                msg.Message = "Script is valid.";
                messages.Add(msg);
            }

            return(messages);
        }
Пример #19
0
        private static Keyword GetResetNodeFlag()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "resetNodeFlag";
            keyword.FriendlyName = "Reset Node Flag";
            keyword.HelpText = "Used to set a nodes flag as the result of an action.";

            keyword.Inputs.Add(new KeywordInput(KeywordInputType.Node, "Node ID", "The ID of the Action for which the objective is associated."));
            keyword.Inputs.Add(new KeywordInput(KeywordInputType.Flag, "Flag", "The new node flag value."));

            return keyword;
        }
        public ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            _keywords = KeywordFactory.GetKeywords();

            // the keyword factory just has the non-required words
            _keywords.Add(new Keyword("bot_SightDist", "", "How far the highest skill bot can see on this map", false));

            ArrayList allowable = new ArrayList();
            allowable.Add("0");
            allowable.Add("1");

            Keyword flag = new Keyword("spawnflag_is_priority", "",  "Whether or no bots focus on spawnflags.", false);
            KeywordInput flagInput = new KeywordInput(KeywordInputType.PredefinedList, "spawnflag_is_priority", "Whether or no bots focus on spawnflags.");
            flagInput.AllowableValues = allowable;
            flag.Inputs.Add(flagInput);
            _keywords.Add(flag);

            Keyword cmdpost = new Keyword("cmdpost_is_priority", "",  "Whether or not command posts critical on this map.", false);
            KeywordInput cmdpostInput = new KeywordInput(KeywordInputType.PredefinedList, "cmdpost_is_priority", "Whether or not command posts critical on this map.");
            cmdpostInput.AllowableValues = allowable;
            cmdpost.Inputs.Add(cmdpostInput);
            _keywords.Add(cmdpost);

            Keyword construct = new Keyword("construct_is_priority", "",  "Whether or not engineers focus more on constructibles.", false);
            KeywordInput constructInput = new KeywordInput(KeywordInputType.PredefinedList, "construct_is_priority", "Whether or not engineers focus more on constructibles.");
            constructInput.AllowableValues = allowable;
            construct.Inputs.Add(constructInput);
            _keywords.Add(construct);

            Keyword vehicle = new Keyword("map_has_vehicle", "",  "Whether or not this map has a tank or a train.", false);
            KeywordInput vehicleInput = new KeywordInput(KeywordInputType.PredefinedList, "map_has_vehicle", "Type of vehicle 0 = none, 1 = tank, 2 = train");

            ArrayList allowableVehicle = new ArrayList();
            allowable.Add("0");
            allowable.Add("1");
            allowable.Add("2");
            vehicleInput.AllowableValues = allowableVehicle;
            vehicle.Inputs.Add(vehicleInput);
            _keywords.Add(vehicle);

            //vehicle_entity_number 429 //the entity number of the tank
            Keyword vehicleEntity = new Keyword("vehicle_entity_number", "",  "The entity number of the vehicle.", false);
            vehicleEntity.Inputs.Add(new KeywordInput(KeywordInputType.Action, "Vehicle Entity Number", "The entity number of the vehicle."));
            _keywords.Add(vehicleEntity);

            //vehicle_team_owner 2 //ALLIES own this tank! 1 = AXIS, 2 = ALLIES
            Keyword vehicleOwner = new Keyword("vehicle_team_owner", "",  "The owner of the vehicle.", false);
            KeywordInput vehicleOwnerInput = new KeywordInput(KeywordInputType.PredefinedList, "vehicle_team_owner", "1 = AXIS, 2 = ALLIES.");
            vehicleOwnerInput.AllowableValues.Add("1");;
            vehicleOwnerInput.AllowableValues.Add("2");;
            vehicleOwner.Inputs.Add(vehicleOwnerInput);
            _keywords.Add(vehicleOwner);

            _keywords.Sort(KeywordComparer.SortBy.Command);

            _textArea = textArea;
            _typedChar = charTyped;

            // see if a word on the line the input was in is a keyword that we have,
            // then figure out what input they are at
            LineSegment line = textArea.Document.GetLineSegmentForOffset(textArea.Caret.Offset);

            bool keywordFound = false;
            if (line != null)
            {
                TextWord first = GetWord(line, 1);

                if (first != null)
                {
                    Keyword keyword = _keywords.GetWord(first.Word);

                    if (keyword != null)
                    {
                        keywordFound = true;
                        if (keyword.Inputs.Count > 0)
                        {
                            for (int x = 0; x < keyword.Inputs.Count; x++)
                            {
                                TextWord param = GetWord(line, x + 2);

                                if (param == null)
                                {
                                    KeywordInput inputParam = (KeywordInput)keyword.Inputs[x];

                                    if (inputParam.InputType == KeywordInputType.PredefinedList)
                                    {
                                        ICompletionData[] data = new ICompletionData[inputParam.AllowableValues.Count];

                                        for (int y = 0; y < inputParam.AllowableValues.Count; y++)
                                        {
                                            Keyword dummyKeyword = new Keyword((string)inputParam.AllowableValues[y], (string)inputParam.AllowableValues[y], inputParam.HelpText, false);
                                            data[y] = new KeywordCompletionData(dummyKeyword);
                                        }

                                        return data;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (keywordFound)
            {
                return null;
            }

            // fall through, return all keywords
            ICompletionData[] all = new ICompletionData[_keywords.Count];

            for (int x = 0; x < _keywords.Count; x++)
            {
                all[x] = new KeywordCompletionData(_keywords[x]);
            }

            return all;
        }
Пример #21
0
        //crapshoot: set_Map_Has_Vehicle
        private static Keyword GetSetMapHasVehicle()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "set_Map_Has_Vehicle";
            keyword.FriendlyName = "Map Has Vehicle";
            keyword.HelpText = "Used for turning movers on and off";

            KeywordInput input = new KeywordInput(KeywordInputType.PredefinedList, "Has Vehicle", "Whether or not a Vehicle is active.");
            input.AllowableValues.Add("true");
            input.AllowableValues.Add("false");
            keyword.Inputs.Add(input);

            return keyword;
        }
Пример #22
0
 public bool Contains(Keyword keyword)
 {
     return base.InnerList.Contains(keyword);
 }
Пример #23
0
        private static Keyword GetBotSwitchToWeap()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "bot_switchToWeap";
            keyword.FriendlyName = "Switch Weapons";
            keyword.HelpText = "Will cause all soldiers on the specified team to switch to the defined weapon.";

            KeywordInput weapon = new KeywordInput(KeywordInputType.PredefinedList, "Weapon", "The weapon to switch to.");
            weapon.AllowableValues.Add("FG42");
            weapon.AllowableValues.Add("flame");
            weapon.AllowableValues.Add("garand");
            weapon.AllowableValues.Add("k43");
            weapon.AllowableValues.Add("MG42");
            weapon.AllowableValues.Add("mortar");
            weapon.AllowableValues.Add("panzer");
            weapon.AllowableValues.Add("random");
            weapon.AllowableValues.Add("random_f");
            weapon.AllowableValues.Add("random_fp");
            weapon.AllowableValues.Add("random_p");
            weapon.AllowableValues.Add("random_pf");
            weapon.AllowableValues.Add("smg");
            weapon.AllowableValues.Add("sniper");
            weapon.AllowableValues.Add("venom");

            keyword.Inputs.Add(weapon);

            KeywordInput team = new KeywordInput(KeywordInputType.PredefinedList, "Team", "The team to switch weapons for");
            team.AllowableValues.Add("allies");
            team.AllowableValues.Add("axis");

            keyword.Inputs.Add(team);

            return keyword;
        }
Пример #24
0
 public int IndexOf(Keyword keyword)
 {
     return base.InnerList.IndexOf(keyword);
 }
Пример #25
0
        //crapshoot: set_Vehicle_Owner
        private static Keyword GetSetVehicleOwner()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "set_Vehicle_Owner";
            keyword.FriendlyName = "Vehicle Owner";
            keyword.HelpText = "Who owns the vehicle?";

            KeywordInput input = new KeywordInput(KeywordInputType.PredefinedList, "Vehicle Owner", "Who Owns the Vehicle");
            input.AllowableValues.Add("allies");
            input.AllowableValues.Add("axis");
            keyword.Inputs.Add(input);

            return keyword;
        }
Пример #26
0
 public void Remove(Keyword keyword)
 {
     RemoveLookupWord(keyword);
     base.InnerList.Remove(keyword);
 }
Пример #27
0
        private static Keyword GetWaitCommand()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "wait";
            keyword.FriendlyName = "Wait";
            keyword.HelpText = "Used to wait a specified period (in seconds) before executing the next lines command.";

            KeywordInput seconds = new KeywordInput(KeywordInputType.Integer, "Seconds", "The amount of seconds to wait before executing the next command.");
            keyword.Inputs.Add(seconds);

            return keyword;
        }
Пример #28
0
        //crapshoot: set_Vehicle_Number
        private static Keyword GetSetVehicleNumber()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "set_Vehicle_Number";
            keyword.FriendlyName = "Vehicle Number";
            keyword.HelpText = "The entity number of the vehicle (script_mover)";

            KeywordInput entity = new KeywordInput(KeywordInputType.Integer, "Entity Number", "Entity Number for Vehicle.");
            keyword.Inputs.Add(entity);

            return keyword;
        }
Пример #29
0
        private static Keyword GetIfAxisCpBuiltTrue()
        {
            Keyword keyword = new Keyword();

            keyword.Command = "if_axis_cp_built_true";
            keyword.FriendlyName = "If Axis Command Post Built";
            keyword.HelpText = "Used for determining if an Axis Command Post is built.";
            keyword.AllowConditional = true;

            KeywordInput action = new KeywordInput(KeywordInputType.Action, "Action ID", "The ID of the Action for which the objective is associated.");
            action.AllowableActions.Add(22);

            keyword.Inputs.Add(action);

            return keyword;
        }