コード例 #1
0
        private string _lastFile; //crapshoot

        //new method to open last nav file -crapshoot
        private void openLastNav()
        {
            try
            {
                UserData userData = AppData.UserDataLoad();

                if (userData != null)
                {
                    //i'm saving full path now
                    _lastFile = userData.LastNavDirectory;

                    try
                    {
                        _reader = new NavigationReader();
                        _reader.Read(_lastFile);
                        _navFileName = _lastFile;
                    }
                    catch
                    {
                        InitializeWaypoints(false);
                    }
                }
                //made it, so initialize
                this.Text = "Fritz Waypoint Tool (ET) - " + _lastFile;
                InitializeWaypoints(true);
            }
            catch
            {
                InitializeWaypoints(false);
            }
        }
コード例 #2
0
        public void InitializeWaypoints(NavigationReader reader)
        {
            this.SuspendLayout();
            _nodeControl      = new NodeControl();
            _nodeControl.Dock = DockStyle.Fill;

            _actionControl      = new ActionControl();
            _actionControl.Dock = DockStyle.Fill;

            _routeControl      = new RouteControl();
            _routeControl.Dock = DockStyle.Fill;

            TabPage nodes = new TabPage("Nodes");

            nodes.Controls.Add(_nodeControl);

            TabPage actions = new TabPage("Actions");

            actions.Controls.Add(_actionControl);

            TabPage routes = new TabPage("Routes");

            routes.Controls.Add(_routeControl);

            tcMain.TabPages.Clear();
            tcMain.TabPages.Add(nodes);
            tcMain.TabPages.Add(actions);
            tcMain.TabPages.Add(routes);

            _nodeControl.InitializeNodes(reader.Nodes, reader.HasBadConnects);
            _actionControl.InitializeActions(reader.Actions);
            _routeControl.InitializeRoutes(reader.Routes, _actionControl.Actions);

            this.ResumeLayout(false);

            try
            {
                if (System.Drawing.Printing.PrinterSettings.InstalledPrinters.Count > 0)
                {
                    _nodePrinter   = new NodePrinter(printDocument, _nodeControl.Nodes, Path.GetFileName(reader.FileName));
                    _actionPrinter = new ActionPrinter(printDocument, _actionControl.Actions, Path.GetFileName(reader.FileName));
                    _routePrinter  = new RoutePrinter(printDocument, _routeControl.Routes, Path.GetFileName(reader.FileName));
                }
            }
            catch
            {
            }
        }
コード例 #3
0
ファイル: WaypointControl.cs プロジェクト: fishxz/omni-bot
        public void InitializeWaypoints(NavigationReader reader)
        {
            this.SuspendLayout();
            _nodeControl = new NodeControl();
            _nodeControl.Dock = DockStyle.Fill;

            _actionControl = new ActionControl();
            _actionControl.Dock = DockStyle.Fill;

            _routeControl = new RouteControl();
            _routeControl.Dock = DockStyle.Fill;

            TabPage nodes = new TabPage("Nodes");
            nodes.Controls.Add(_nodeControl);

            TabPage actions = new TabPage("Actions");
            actions.Controls.Add(_actionControl);

            TabPage routes = new TabPage("Routes");
            routes.Controls.Add(_routeControl);

            tcMain.TabPages.Clear();
            tcMain.TabPages.Add(nodes);
            tcMain.TabPages.Add(actions);
            tcMain.TabPages.Add(routes);

            _nodeControl.InitializeNodes(reader.Nodes, reader.HasBadConnects);
            _actionControl.InitializeActions(reader.Actions);
            _routeControl.InitializeRoutes(reader.Routes, _actionControl.Actions);

            this.ResumeLayout(false);

            try
            {
                if (System.Drawing.Printing.PrinterSettings.InstalledPrinters.Count > 0)
                {
                    _nodePrinter = new NodePrinter(printDocument, _nodeControl.Nodes, Path.GetFileName(reader.FileName));
                    _actionPrinter = new ActionPrinter(printDocument, _actionControl.Actions, Path.GetFileName(reader.FileName));
                    _routePrinter = new RoutePrinter(printDocument, _routeControl.Routes, Path.GetFileName(reader.FileName));
                }
            }
            catch
            {
            }
        }
コード例 #4
0
        //end crapshoot


        private void mnuReadNav_Click(object sender, System.EventArgs e)
        {
            try
            {
                UserData userData = AppData.UserDataLoad();

                if (userData != null)
                {
                    openFileDialog.InitialDirectory = userData.LastNavDirectory;
                }

                openFileDialog.Filter = "Fritz Navigation Files(*.nav)|*.nav";
                openFileDialog.ShowDialog(this);

                if (openFileDialog.FileName != null && openFileDialog.FileName.Trim().Length > 0)
                {
                    if (userData == null)
                    {
                        userData = new UserData();
                    }
                    //save the full path so we can load last file -crapshoot
                    userData.LastNavDirectory = Path.GetFullPath(openFileDialog.FileName);
                    AppData.UserDataSave(userData);

                    _reader = new NavigationReader();
                    _reader.Read(openFileDialog.FileName);
                    _navFileName = openFileDialog.FileName;

                    this.Text = "Fritz Waypoint Tool (ET) - " + _navFileName;

                    InitializeWaypoints(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Unable to read .nav file. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #5
0
ファイル: NavigationDiff.cs プロジェクト: fishxz/omni-bot
        public void DoDiff(NavigationReader left, NavigationReader right)
        {
            int nodeIndex = 0;
            int rightNodeIndex = right.Nodes.Count - 1;
            int rightActionIndex = right.Actions.Count - 1;
            int rightRouteIndex = right.Routes.Count - 1;

            foreach (Node leftNode in left.Nodes)
            {
                if (nodeIndex <= rightNodeIndex)
                {
                    Node rightNode = (Node)right.Nodes[nodeIndex];

                    if (!leftNode.Equals(rightNode))
                    {
                        _differentNodes.Add(new NodeDifference(leftNode, rightNode));
                    }
                }
                else
                {
                    _differentNodes.Add(new NodeDifference(leftNode, null));
                }

                nodeIndex++;
            }

            if (nodeIndex <= rightNodeIndex)
            {
                for (int x = nodeIndex; x < right.Nodes.Count; x++)
                {
                    _differentNodes.Add(new NodeDifference(null, (Node)right.Nodes[x]));
                }
            }

            int actionIndex = 0;

            foreach (Action leftAction in left.Actions)
            {
                if (actionIndex <= rightActionIndex)
                {
                    Action rightAction = (Action)right.Actions[actionIndex];

                    if (!leftAction.Equals(rightAction))
                    {
                        _differentActions.Add(new ActionDifference(leftAction, rightAction));
                    }
                }
                else
                {
                    _differentActions.Add(new ActionDifference(leftAction, null));
                }

                actionIndex++;
            }

            if (actionIndex <= rightActionIndex)
            {
                for (int x = actionIndex; x < right.Actions.Count; x++)
                {
                    _differentActions.Add(new ActionDifference(null, (Action)right.Actions[x]));
                }
            }

            int routeIndex = 0;
            foreach (Route leftRoute in left.Routes)
            {
                if (routeIndex <= rightRouteIndex)
                {
                    Route rightRoute = (Route)right.Routes[routeIndex];

                    if (!leftRoute.Equals(rightRoute))
                    {
                        _differentRoutes.Add(new RouteDifference(leftRoute, rightRoute));
                    }
                }
                else
                {
                    _differentRoutes.Add(new RouteDifference(leftRoute, null));
                }

                routeIndex++;
            }

            if (routeIndex <= rightRouteIndex)
            {
                for (int x = routeIndex; x < right.Routes.Count; x++)
                {
                    _differentRoutes.Add(new RouteDifference(null, (Route)right.Routes[x]));
                }
            }
        }
コード例 #6
0
ファイル: AIScriptValidator.cs プロジェクト: fishxz/omni-bot
        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;
        }
コード例 #7
0
        public void DoDiff(NavigationReader left, NavigationReader right)
        {
            int nodeIndex        = 0;
            int rightNodeIndex   = right.Nodes.Count - 1;
            int rightActionIndex = right.Actions.Count - 1;
            int rightRouteIndex  = right.Routes.Count - 1;

            foreach (Node leftNode in left.Nodes)
            {
                if (nodeIndex <= rightNodeIndex)
                {
                    Node rightNode = (Node)right.Nodes[nodeIndex];

                    if (!leftNode.Equals(rightNode))
                    {
                        _differentNodes.Add(new NodeDifference(leftNode, rightNode));
                    }
                }
                else
                {
                    _differentNodes.Add(new NodeDifference(leftNode, null));
                }

                nodeIndex++;
            }

            if (nodeIndex <= rightNodeIndex)
            {
                for (int x = nodeIndex; x < right.Nodes.Count; x++)
                {
                    _differentNodes.Add(new NodeDifference(null, (Node)right.Nodes[x]));
                }
            }

            int actionIndex = 0;

            foreach (Action leftAction in left.Actions)
            {
                if (actionIndex <= rightActionIndex)
                {
                    Action rightAction = (Action)right.Actions[actionIndex];

                    if (!leftAction.Equals(rightAction))
                    {
                        _differentActions.Add(new ActionDifference(leftAction, rightAction));
                    }
                }
                else
                {
                    _differentActions.Add(new ActionDifference(leftAction, null));
                }

                actionIndex++;
            }

            if (actionIndex <= rightActionIndex)
            {
                for (int x = actionIndex; x < right.Actions.Count; x++)
                {
                    _differentActions.Add(new ActionDifference(null, (Action)right.Actions[x]));
                }
            }

            int routeIndex = 0;

            foreach (Route leftRoute in left.Routes)
            {
                if (routeIndex <= rightRouteIndex)
                {
                    Route rightRoute = (Route)right.Routes[routeIndex];

                    if (!leftRoute.Equals(rightRoute))
                    {
                        _differentRoutes.Add(new RouteDifference(leftRoute, rightRoute));
                    }
                }
                else
                {
                    _differentRoutes.Add(new RouteDifference(leftRoute, null));
                }

                routeIndex++;
            }

            if (routeIndex <= rightRouteIndex)
            {
                for (int x = routeIndex; x < right.Routes.Count; x++)
                {
                    _differentRoutes.Add(new RouteDifference(null, (Route)right.Routes[x]));
                }
            }
        }
コード例 #8
0
ファイル: FormMain.cs プロジェクト: fishxz/omni-bot
        private void mnuReadNav_Click(object sender, System.EventArgs e)
        {
            try
            {
                UserData userData = AppData.UserDataLoad();

                if (userData != null)
                {
                    openFileDialog.InitialDirectory = userData.LastNavDirectory;
                }

                openFileDialog.Filter = "Fritz Navigation Files(*.nav)|*.nav";
                openFileDialog.ShowDialog(this);

                if (openFileDialog.FileName != null && openFileDialog.FileName.Trim().Length > 0)
                {
                    if (userData == null)
                    {
                        userData = new UserData();
                    }
                    userData.LastNavDirectory = Path.GetDirectoryName(openFileDialog.FileName);
                    AppData.UserDataSave(userData);

                    _reader = new NavigationReader();
                    _reader.Read(openFileDialog.FileName);
                    _navFileName = openFileDialog.FileName;

                    this.Text = "Fritz Waypoint Tool (ET) - " + _navFileName;

                    InitializeWaypoints(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Unable to read .nav file. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #9
0
        private void btnCompare_Click(object sender, System.EventArgs e)
        {
            try
            {
                txtSummary.Clear();

                if (txtNavigationFile1.Text.Trim().Length == 0 ||
                    txtNavigationFile2.Text.Trim().Length == 0)
                {
                    MessageBox.Show(this.ParentForm, "Please choose two files to compare.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                NavigationReader left  = new NavigationReader();
                NavigationReader right = new NavigationReader();

                left.Read(txtNavigationFile1.Text);
                right.Read(txtNavigationFile2.Text);

                NavigationDiff diff = new NavigationDiff();
                diff.DoDiff(left, right);

                if (diff.DifferentActions.Count == 0 && diff.DifferentNodes.Count == 0 && diff.DifferentRoutes.Count == 0)
                {
                    txtSummary.AppendText("The navigation files are the same.");
                    return;
                }

                foreach (NodeDifference nodeDiff in diff.DifferentNodes)
                {
                    if (nodeDiff.LeftNode == null)
                    {
                        txtSummary.AppendText("Left Navigation is missing Node " + nodeDiff.RightNode.ID + "\r\n\r\n");
                    }
                    else if (nodeDiff.RightNode == null)
                    {
                        txtSummary.AppendText("Right Navigation is missing Node " + nodeDiff.LeftNode.ID + "\r\n\r\n");
                    }
                    else
                    {
                        txtSummary.AppendText("Node " + nodeDiff.LeftNode.ID + " is different.\r\n");

                        if (nodeDiff.LeftNode.Connect1 != nodeDiff.RightNode.Connect1)
                        {
                            txtSummary.AppendText("\tLeft Connect 1 = " + nodeDiff.LeftNode.Connect1 + ", Right Connect 1 = " + nodeDiff.RightNode.Connect1 + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Connect2 != nodeDiff.RightNode.Connect2)
                        {
                            txtSummary.AppendText("\tLeft Connect 2 = " + nodeDiff.LeftNode.Connect2 + ", Right Connect 2 = " + nodeDiff.RightNode.Connect2 + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Connect3 != nodeDiff.RightNode.Connect3)
                        {
                            txtSummary.AppendText("\tLeft Connect 3 = " + nodeDiff.LeftNode.Connect3 + ", Right Connect 3 = " + nodeDiff.RightNode.Connect3 + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Connect4 != nodeDiff.RightNode.Connect4)
                        {
                            txtSummary.AppendText("\tLeft Connect 4 = " + nodeDiff.LeftNode.Connect4 + ", Right Connect 4 = " + nodeDiff.RightNode.Connect4 + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Entity != nodeDiff.RightNode.Entity)
                        {
                            txtSummary.AppendText("\tLeft Entity = " + nodeDiff.LeftNode.Entity + ", Right Entity = " + nodeDiff.RightNode.Entity + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Flags != nodeDiff.RightNode.Flags)
                        {
                            txtSummary.AppendText("\tLeft Flags = " + nodeDiff.LeftNode.Flags + ", Right Flags = " + nodeDiff.RightNode.Flags + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Group != nodeDiff.RightNode.Group)
                        {
                            txtSummary.AppendText("\tLeft Group = " + nodeDiff.LeftNode.Group + ", Right Group = " + nodeDiff.RightNode.Group + "\r\n");
                        }

                        if (nodeDiff.LeftNode.NumberOfConnects != nodeDiff.RightNode.NumberOfConnects)
                        {
                            txtSummary.AppendText("\tLeft Number of Connections = " + nodeDiff.LeftNode.NumberOfConnects + ", Right Number of Connections = " + nodeDiff.RightNode.NumberOfConnects + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Radius != nodeDiff.RightNode.Radius)
                        {
                            txtSummary.AppendText("\tLeft Radius = " + nodeDiff.LeftNode.Radius + ", Right Radius = " + nodeDiff.RightNode.Radius + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Team != nodeDiff.RightNode.Team)
                        {
                            txtSummary.AppendText("\tLeft Team = " + nodeDiff.LeftNode.Team + ", Right Team = " + nodeDiff.RightNode.Team + "\r\n");
                        }
                    }
                }

                foreach (ActionDifference actionDiff in diff.DifferentActions)
                {
                    if (actionDiff.LeftAction == null)
                    {
                        txtSummary.AppendText("Left Navigation is missing Action " + actionDiff.RightAction.ID + "\r\n\r\n");
                    }
                    else if (actionDiff.RightAction == null)
                    {
                        txtSummary.AppendText("Right Navigation is missing Action " + actionDiff.LeftAction.ID + "\r\n\r\n");
                    }
                    else
                    {
                        txtSummary.AppendText("Action " + actionDiff.LeftAction.ID + " is different.\r\n");

                        if (actionDiff.LeftAction.Active != actionDiff.RightAction.Active)
                        {
                            txtSummary.AppendText("\tLeft Active = " + actionDiff.LeftAction.Active + ", Right Active = " + actionDiff.RightAction.Active + "\r\n");
                        }

                        if (actionDiff.LeftAction.AllyAction != actionDiff.RightAction.AllyAction)
                        {
                            txtSummary.AppendText("\tLeft Ally Action = " + actionDiff.LeftAction.AllyAction + ", Right Ally Action = " + actionDiff.RightAction.AllyAction + "\r\n");
                        }

                        if (actionDiff.LeftAction.AxisAction != actionDiff.RightAction.AxisAction)
                        {
                            txtSummary.AppendText("\tLeft Axis Action = " + actionDiff.LeftAction.AxisAction + ", Right Axis Action = " + actionDiff.RightAction.AxisAction + "\r\n");
                        }

                        if (actionDiff.LeftAction.Class != actionDiff.RightAction.Class)
                        {
                            txtSummary.AppendText("\tLeft Class = " + actionDiff.LeftAction.Class + ", Right Class = " + actionDiff.RightAction.Class + "\r\n");
                        }

                        if (actionDiff.LeftAction.CloseNode != actionDiff.RightAction.CloseNode)
                        {
                            txtSummary.AppendText("\tLeft Close Node = " + actionDiff.LeftAction.CloseNode + ", Right Close Node = " + actionDiff.RightAction.CloseNode + "\r\n");
                        }

                        if (actionDiff.LeftAction.Entity != actionDiff.RightAction.Entity)
                        {
                            txtSummary.AppendText("\tLeft Entity = " + actionDiff.LeftAction.Entity + ", Right Entity = " + actionDiff.RightAction.Entity + "\r\n");
                        }

                        if (actionDiff.LeftAction.Goal != actionDiff.RightAction.Goal)
                        {
                            txtSummary.AppendText("\tLeft Goal = " + actionDiff.LeftAction.Goal + ", Right Goal = " + actionDiff.RightAction.Goal + "\r\n");
                        }

                        if (actionDiff.LeftAction.Group != actionDiff.RightAction.Group)
                        {
                            txtSummary.AppendText("\tLeft Group = " + actionDiff.LeftAction.Group + ", Right Group = " + actionDiff.RightAction.Group + "\r\n");
                        }

                        if (actionDiff.LeftAction.Links != actionDiff.RightAction.Links)
                        {
                            txtSummary.AppendText("\tLeft Links = " + actionDiff.LeftAction.Links + ", Right Links = " + actionDiff.RightAction.Links + "\r\n");
                        }

                        if (actionDiff.LeftAction.Prone != actionDiff.RightAction.Prone)
                        {
                            txtSummary.AppendText("\tLeft Prone = " + actionDiff.LeftAction.Prone + ", Right Prone = " + actionDiff.RightAction.Prone + "\r\n");
                        }

                        if (actionDiff.LeftAction.Radius != actionDiff.RightAction.Radius)
                        {
                            txtSummary.AppendText("\tLeft Radius = " + actionDiff.LeftAction.Radius + ", Right Radius = " + actionDiff.RightAction.Radius + "\r\n");
                        }
                    }
                }

                foreach (RouteDifference routeDiff in diff.DifferentRoutes)
                {
                    if (routeDiff.LeftRoute == null)
                    {
                        txtSummary.AppendText("Left Navigation is missing Route " + routeDiff.RightRoute.ID + "\r\n\r\n");
                    }
                    else if (routeDiff.RightRoute == null)
                    {
                        txtSummary.AppendText("Right Navigation is missing Route " + routeDiff.LeftRoute.ID + "\r\n\r\n");
                    }
                    else
                    {
                        txtSummary.AppendText("Route " + routeDiff.LeftRoute.ID + " is different.\r\n");

                        if (routeDiff.LeftRoute.Team != routeDiff.RightRoute.Team)
                        {
                            txtSummary.AppendText("\tLeft Team = " + routeDiff.LeftRoute.Team + ", Right Team = " + routeDiff.RightRoute.Team + "\r\n");
                        }

                        if (routeDiff.LeftRoute.Radius != routeDiff.RightRoute.Radius)
                        {
                            txtSummary.AppendText("\tLeft Radius = " + routeDiff.LeftRoute.Radius + ", Right Radius = " + routeDiff.RightRoute.Radius + "\r\n");
                        }

                        if (routeDiff.LeftRoute.Actions != routeDiff.RightRoute.Actions)
                        {
                            txtSummary.AppendText("\tLeft Actions = " + routeDiff.LeftRoute.Actions + ", Right Actions = " + routeDiff.RightRoute.Actions + "\r\n");
                        }

                        if (routeDiff.LeftRoute.PathActions != routeDiff.RightRoute.PathActions)
                        {
                            txtSummary.AppendText("\tLeft PathActions = " + routeDiff.LeftRoute.PathActions + ", Right PathActions = " + routeDiff.RightRoute.PathActions + "\r\n");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ParentForm, "Error comparing navigation files. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #10
0
ファイル: FormMain.cs プロジェクト: fishxz/omni-bot
        //new method to open last nav file -crapshoot
        private void openLastNav()
        {
            try
            {
                UserData userData = AppData.UserDataLoad();

                if (userData != null)
                {
                    //i'm saving full path now
                    _lastFile = userData.LastNavDirectory;

                    try
                    {
                        _reader = new NavigationReader();
                        _reader.Read(_lastFile);
                        _navFileName = _lastFile;
                    }
                    catch
                    {
                        InitializeWaypoints(false);
                    }
                }
                //made it, so initialize
                this.Text = "Fritz Waypoint Tool (ET) - " + _lastFile;
                InitializeWaypoints(true);
            }
            catch
            {
                InitializeWaypoints(false);
            }
        }
コード例 #11
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);
        }
コード例 #12
0
        private void btnCompare_Click(object sender, System.EventArgs e)
        {
            try
            {
                txtSummary.Clear();

                if (txtNavigationFile1.Text.Trim().Length == 0 ||
                    txtNavigationFile2.Text.Trim().Length == 0)
                {
                    MessageBox.Show(this.ParentForm, "Please choose two files to compare.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                NavigationReader left = new NavigationReader();
                NavigationReader right = new NavigationReader();

                left.Read(txtNavigationFile1.Text);
                right.Read(txtNavigationFile2.Text);

                NavigationDiff diff = new NavigationDiff();
                diff.DoDiff(left, right);

                if (diff.DifferentActions.Count == 0 && diff.DifferentNodes.Count == 0 && diff.DifferentRoutes.Count == 0)
                {
                    txtSummary.AppendText("The navigation files are the same.");
                    return;
                }

                foreach (NodeDifference nodeDiff in diff.DifferentNodes)
                {
                    if (nodeDiff.LeftNode == null)
                    {
                        txtSummary.AppendText("Left Navigation is missing Node " + nodeDiff.RightNode.ID + "\r\n\r\n");
                    }
                    else if (nodeDiff.RightNode == null)
                    {
                        txtSummary.AppendText("Right Navigation is missing Node " + nodeDiff.LeftNode.ID + "\r\n\r\n");
                    }
                    else
                    {
                        txtSummary.AppendText("Node " + nodeDiff.LeftNode.ID + " is different.\r\n");

                        if (nodeDiff.LeftNode.Connect1 != nodeDiff.RightNode.Connect1)
                        {
                            txtSummary.AppendText("\tLeft Connect 1 = " + nodeDiff.LeftNode.Connect1 + ", Right Connect 1 = " + nodeDiff.RightNode.Connect1 + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Connect2 != nodeDiff.RightNode.Connect2)
                        {
                            txtSummary.AppendText("\tLeft Connect 2 = " + nodeDiff.LeftNode.Connect2 + ", Right Connect 2 = " + nodeDiff.RightNode.Connect2 + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Connect3 != nodeDiff.RightNode.Connect3)
                        {
                            txtSummary.AppendText("\tLeft Connect 3 = " + nodeDiff.LeftNode.Connect3 + ", Right Connect 3 = " + nodeDiff.RightNode.Connect3 + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Connect4 != nodeDiff.RightNode.Connect4)
                        {
                            txtSummary.AppendText("\tLeft Connect 4 = " + nodeDiff.LeftNode.Connect4 + ", Right Connect 4 = " + nodeDiff.RightNode.Connect4 + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Entity != nodeDiff.RightNode.Entity)
                        {
                            txtSummary.AppendText("\tLeft Entity = " + nodeDiff.LeftNode.Entity + ", Right Entity = " + nodeDiff.RightNode.Entity + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Flags != nodeDiff.RightNode.Flags)
                        {
                            txtSummary.AppendText("\tLeft Flags = " + nodeDiff.LeftNode.Flags + ", Right Flags = " + nodeDiff.RightNode.Flags + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Group != nodeDiff.RightNode.Group)
                        {
                            txtSummary.AppendText("\tLeft Group = " + nodeDiff.LeftNode.Group + ", Right Group = " + nodeDiff.RightNode.Group + "\r\n");
                        }

                        if (nodeDiff.LeftNode.NumberOfConnects != nodeDiff.RightNode.NumberOfConnects)
                        {
                            txtSummary.AppendText("\tLeft Number of Connections = " + nodeDiff.LeftNode.NumberOfConnects + ", Right Number of Connections = " + nodeDiff.RightNode.NumberOfConnects + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Radius != nodeDiff.RightNode.Radius)
                        {
                            txtSummary.AppendText("\tLeft Radius = " + nodeDiff.LeftNode.Radius + ", Right Radius = " + nodeDiff.RightNode.Radius + "\r\n");
                        }

                        if (nodeDiff.LeftNode.Team != nodeDiff.RightNode.Team)
                        {
                            txtSummary.AppendText("\tLeft Team = " + nodeDiff.LeftNode.Team + ", Right Team = " + nodeDiff.RightNode.Team + "\r\n");
                        }
                    }
                }

                foreach (ActionDifference actionDiff in diff.DifferentActions)
                {
                    if (actionDiff.LeftAction == null)
                    {
                        txtSummary.AppendText("Left Navigation is missing Action " + actionDiff.RightAction.ID + "\r\n\r\n");
                    }
                    else if (actionDiff.RightAction == null)
                    {
                        txtSummary.AppendText("Right Navigation is missing Action " + actionDiff.LeftAction.ID + "\r\n\r\n");
                    }
                    else
                    {
                        txtSummary.AppendText("Action " + actionDiff.LeftAction.ID + " is different.\r\n");

                        if (actionDiff.LeftAction.Active != actionDiff.RightAction.Active)
                        {
                            txtSummary.AppendText("\tLeft Active = " + actionDiff.LeftAction.Active + ", Right Active = " + actionDiff.RightAction.Active + "\r\n");
                        }

                        if (actionDiff.LeftAction.AllyAction != actionDiff.RightAction.AllyAction)
                        {
                            txtSummary.AppendText("\tLeft Ally Action = " + actionDiff.LeftAction.AllyAction + ", Right Ally Action = " + actionDiff.RightAction.AllyAction + "\r\n");
                        }

                        if (actionDiff.LeftAction.AxisAction != actionDiff.RightAction.AxisAction)
                        {
                            txtSummary.AppendText("\tLeft Axis Action = " + actionDiff.LeftAction.AxisAction + ", Right Axis Action = " + actionDiff.RightAction.AxisAction + "\r\n");
                        }

                        if (actionDiff.LeftAction.Class != actionDiff.RightAction.Class)
                        {
                            txtSummary.AppendText("\tLeft Class = " + actionDiff.LeftAction.Class + ", Right Class = " + actionDiff.RightAction.Class + "\r\n");
                        }

                        if (actionDiff.LeftAction.CloseNode != actionDiff.RightAction.CloseNode)
                        {
                            txtSummary.AppendText("\tLeft Close Node = " + actionDiff.LeftAction.CloseNode + ", Right Close Node = " + actionDiff.RightAction.CloseNode + "\r\n");
                        }

                        if (actionDiff.LeftAction.Entity != actionDiff.RightAction.Entity)
                        {
                            txtSummary.AppendText("\tLeft Entity = " + actionDiff.LeftAction.Entity + ", Right Entity = " + actionDiff.RightAction.Entity + "\r\n");
                        }

                        if (actionDiff.LeftAction.Goal != actionDiff.RightAction.Goal)
                        {
                            txtSummary.AppendText("\tLeft Goal = " + actionDiff.LeftAction.Goal + ", Right Goal = " + actionDiff.RightAction.Goal + "\r\n");
                        }

                        if (actionDiff.LeftAction.Group != actionDiff.RightAction.Group)
                        {
                            txtSummary.AppendText("\tLeft Group = " + actionDiff.LeftAction.Group + ", Right Group = " + actionDiff.RightAction.Group + "\r\n");
                        }

                        if (actionDiff.LeftAction.Links != actionDiff.RightAction.Links)
                        {
                            txtSummary.AppendText("\tLeft Links = " + actionDiff.LeftAction.Links + ", Right Links = " + actionDiff.RightAction.Links + "\r\n");
                        }

                        if (actionDiff.LeftAction.Prone != actionDiff.RightAction.Prone)
                        {
                            txtSummary.AppendText("\tLeft Prone = " + actionDiff.LeftAction.Prone + ", Right Prone = " + actionDiff.RightAction.Prone + "\r\n");
                        }

                        if (actionDiff.LeftAction.Radius != actionDiff.RightAction.Radius)
                        {
                            txtSummary.AppendText("\tLeft Radius = " + actionDiff.LeftAction.Radius + ", Right Radius = " + actionDiff.RightAction.Radius + "\r\n");
                        }
                    }
                }

                foreach (RouteDifference routeDiff in diff.DifferentRoutes)
                {
                    if (routeDiff.LeftRoute == null)
                    {
                        txtSummary.AppendText("Left Navigation is missing Route " + routeDiff.RightRoute.ID + "\r\n\r\n");
                    }
                    else if (routeDiff.RightRoute == null)
                    {
                        txtSummary.AppendText("Right Navigation is missing Route " + routeDiff.LeftRoute.ID + "\r\n\r\n");
                    }
                    else
                    {
                        txtSummary.AppendText("Route " + routeDiff.LeftRoute.ID + " is different.\r\n");

                        if (routeDiff.LeftRoute.Team != routeDiff.RightRoute.Team)
                        {
                            txtSummary.AppendText("\tLeft Team = " + routeDiff.LeftRoute.Team + ", Right Team = " + routeDiff.RightRoute.Team + "\r\n");
                        }

                        if (routeDiff.LeftRoute.Radius != routeDiff.RightRoute.Radius)
                        {
                            txtSummary.AppendText("\tLeft Radius = " + routeDiff.LeftRoute.Radius + ", Right Radius = " + routeDiff.RightRoute.Radius + "\r\n");
                        }

                        if (routeDiff.LeftRoute.Actions != routeDiff.RightRoute.Actions)
                        {
                            txtSummary.AppendText("\tLeft Actions = " + routeDiff.LeftRoute.Actions + ", Right Actions = " + routeDiff.RightRoute.Actions + "\r\n");
                        }

                        if (routeDiff.LeftRoute.PathActions != routeDiff.RightRoute.PathActions)
                        {
                            txtSummary.AppendText("\tLeft PathActions = " + routeDiff.LeftRoute.PathActions + ", Right PathActions = " + routeDiff.RightRoute.PathActions + "\r\n");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ParentForm, "Error comparing navigation files. " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #13
0
ファイル: AIScriptEditor.cs プロジェクト: fishxz/omni-bot
        public void InitializeFromReader(NavigationReader reader, bool isNew)
        {
            _reader = reader;

            if (isNew)
            {
                OpenLastFile();
            }
            /* -- don't load this anymore, it seems to be causing lockups.
            Thread thread = new Thread(new ThreadStart(InitializeFromReaderAsync));
            thread.Start();
            */
        }
コード例 #14
0
ファイル: AIScriptEditor.cs プロジェクト: fishxz/omni-bot
        public void InitializeFromReader(NavigationReader reader)
        {
            _reader = reader;

            /* -- don't load this anymore, it seems to be causing lockups.
            Thread thread = new Thread(new ThreadStart(InitializeFromReaderAsync));
            thread.Start();
            */
        }