/// <summary>
        /// Save Button Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            // Get an array of PCO positions
            AiTemplate[] Pcos = (
                from x in WorkingFile.Objects
                where x.Value.TemplateType == TemplateType.AiTemplate
                select x.Value as AiTemplate
                ).ToArray();

            // Set the values of each PCO
            int i = 0;

            foreach (AiTemplate Template in Pcos)
            {
                // Calculate
                int basicTemp = 0, offStr = 0, defStr = 0;
                CalculateValues(PcoValueArray[i++], out basicTemp, out offStr, out defStr);

                // Vehicle strat. strengths are stored in the Unit plugin, so we load that too
                ObjectTemplate plugin = Template.Plugins[AiTemplatePluginType.Unit];

                // Set new values
                plugin.Properties["setStrategicStrength"][0].Values[1] = offStr.ToString();
                plugin.Properties["setStrategicStrength"][1].Values[1] = defStr.ToString();
                Template.Properties["basicTemp"][0].Values[0]          = basicTemp.ToString();
            }

            // Inform User
            MessageBox.Show("Successfully applied settings of all positions!", "Success", MessageBoxButtons.OK);
        }
Ejemplo n.º 2
0
        private void KitAirStrength_Leave(object sender, EventArgs e)
        {
            // The list of AiFiles for this object are stored in the node tag
            Dictionary <AiFileType, AiFile> files = (Dictionary <AiFileType, AiFile>)SelectedNode.Tag;
            ObjectTemplate template = files[AiFileType.Kit].Objects[KitSelect.SelectedItem.ToString()];

            template.Properties["setBattleStrength"][5].Values[1] = KitAirStrength.Value.ToString();
        }
Ejemplo n.º 3
0
        private void WpnHeliStrength_Leave(object sender, EventArgs e)
        {
            // The list of AiFiles for this object are stored in the node tag
            Dictionary <AiFileType, AiFile> files = (Dictionary <AiFileType, AiFile>)SelectedNode.Tag;
            ObjectTemplate template = files[AiFileType.Weapon].Objects[WeaponSelect.SelectedItem.ToString()];

            template.Properties["setStrength"][4].Values[1] = WpnHeliStrength.Value.ToString();
        }
Ejemplo n.º 4
0
        private void MaxRange_Leave(object sender, EventArgs e)
        {
            // The list of AiFiles for this object are stored in the node tag
            Dictionary <AiFileType, AiFile> files = (Dictionary <AiFileType, AiFile>)SelectedNode.Tag;
            ObjectTemplate template = files[AiFileType.Weapon].Objects[WeaponSelect.SelectedItem.ToString()];

            template.Properties["maxRange"][0].Values[0] = MaxRange.Value.ToString();
        }
Ejemplo n.º 5
0
        private void DefStratStrength_Leave(object sender, EventArgs e)
        {
            // The list of AiFiles for this object are stored in the node tag
            Dictionary <AiFileType, AiFile> files = (Dictionary <AiFileType, AiFile>)SelectedNode.Tag;
            AiTemplate template = (AiTemplate)files[AiFileType.Vehicle].Objects[ObjectSelect.SelectedItem.ToString()];

            // Vehicle strat. strengths are stored in the Unit plugin, so we load that too
            ObjectTemplate plugin = template.Plugins[AiTemplatePluginType.Unit];

            plugin.Properties["setStrategicStrength"][1].Values[1] = OffStartStrength.Value.ToString();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Converts the given ObjectTemplate to its File Format
        /// </summary>
        /// <param name="Template"></param>
        /// <param name="Output"></param>
        protected static void BuildObjectString(ObjectTemplate Template, ref StringBuilder Output)
        {
            // Add comment if we have one
            if (!String.IsNullOrWhiteSpace(Template.Comment.Value))
            {
                Output.Append(Template.Comment.Value.TrimEnd());
                Output.AppendLine();
            }

            // Add the create command
            Output.Append(Template.TemplateTypeString + ".create ");

            // Add object type if we have one
            if (Template.ObjectType != "")
            {
                Output.Append(Template.ObjectType + " ");
            }

            // Append the template name
            Output.Append(Template.Name);
            Output.AppendLine();

            // Add properties
            foreach (List <ObjectProperty> Properties in Template.Properties.Values)
            {
                foreach (ObjectProperty Property in Properties)
                {
                    // Add comment if we have one
                    if (!String.IsNullOrWhiteSpace(Property.Comment.Value))
                    {
                        Output.Append(Property.Comment.Value.TrimEnd());
                        Output.AppendLine();
                    }

                    // Entry start
                    Output.Append(Template.TemplateTypeString + "." + Property.Name);
                    foreach (string value in Property.Values)
                    {
                        Output.Append(" " + value);
                    }

                    // Line
                    Output.AppendLine();
                }
            }

            // Trailing lines
            Output.AppendLine();
        }
Ejemplo n.º 7
0
        private void KitSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Make sure its a child node
            if (SelectedNode == null || SelectedNode.Nodes.Count != 0)
            {
                return;
            }

            // The list of AiFiles for this object are stored in the node tag
            Dictionary <AiFileType, AiFile> files = (Dictionary <AiFileType, AiFile>)SelectedNode.Tag;
            ObjectTemplate template = files[AiFileType.Kit].Objects[KitSelect.SelectedItem.ToString()];

            // Set form data
            KitOffStrength.Value      = (int)Double.Parse(template.Properties["setStrategicStrength"][0].Values[1]);
            KitDefStrength.Value      = (int)Double.Parse(template.Properties["setStrategicStrength"][1].Values[1]);
            KitInfantryStrength.Value = Decimal.Parse(template.Properties["setBattleStrength"][0].Values[1]);
            KitLightStrength.Value    = Decimal.Parse(template.Properties["setBattleStrength"][1].Values[1]);
            KitHeavyStrength.Value    = Decimal.Parse(template.Properties["setBattleStrength"][2].Values[1]);
            KitNavalStrength.Value    = Decimal.Parse(template.Properties["setBattleStrength"][3].Values[1]);
            KitHeliStrength.Value     = Decimal.Parse(template.Properties["setBattleStrength"][4].Values[1]);
            KitAirStrength.Value      = Decimal.Parse(template.Properties["setBattleStrength"][5].Values[1]);
        }
Ejemplo n.º 8
0
        private void WeaponSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Make sure its a child node
            if (SelectedNode == null || SelectedNode.Nodes.Count != 0)
            {
                return;
            }

            // The list of AiFiles for this object are stored in the node tag
            Dictionary <AiFileType, AiFile> files = (Dictionary <AiFileType, AiFile>)SelectedNode.Tag;
            ObjectTemplate template = files[AiFileType.Weapon].Objects[WeaponSelect.SelectedItem.ToString()];

            // Set form data
            MinRange.Value            = Decimal.Parse(template.Properties["minRange"][0].Values[0]);
            MaxRange.Value            = Decimal.Parse(template.Properties["maxRange"][0].Values[0]);
            WpnInfantryStrength.Value = Decimal.Parse(template.Properties["setStrength"][0].Values[1]);
            WpnLightStrength.Value    = Decimal.Parse(template.Properties["setStrength"][1].Values[1]);
            WpnHeavyStrength.Value    = Decimal.Parse(template.Properties["setStrength"][2].Values[1]);
            WpnNavalStrength.Value    = Decimal.Parse(template.Properties["setStrength"][3].Values[1]);
            WpnHeliStrength.Value     = Decimal.Parse(template.Properties["setStrength"][4].Values[1]);
            WpnAirPlaneStrength.Value = Decimal.Parse(template.Properties["setStrength"][5].Values[1]);
        }
Ejemplo n.º 9
0
        private void ObjectSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Make sure its a child node
            if (SelectedNode == null || SelectedNode.Nodes.Count != 0)
            {
                return;
            }

            // The list of AiFiles for this object are stored in the node tag
            Dictionary <AiFileType, AiFile> files = (Dictionary <AiFileType, AiFile>)SelectedNode.Tag;
            AiTemplate template = (AiTemplate)files[AiFileType.Vehicle].Objects[ObjectSelect.SelectedItem.ToString()];

            // Vehicle strat. strengths are stored in the Unit plugin, so we load that too
            ObjectTemplate plugin = template.Plugins[AiTemplatePluginType.Unit];

            // [resultNumber( 0 => offense, 1 => defense )][Argument #]
            OffStartStrength.Value = (int)Double.Parse(plugin.Properties["setStrategicStrength"][0].Values[1]);
            DefStratStrength.Value = (int)Double.Parse(plugin.Properties["setStrategicStrength"][1].Values[1]);

            // [entry Name][line #][Argument #]
            ObjectBasicTemp.Value = (int)Int32.Parse(template.Properties["basicTemp"][0].Values[0]);
            Degeneration.Value    = (int)Double.Parse(template.Properties["degeneration"][0].Values[0]);
            AllowedTimeDiff.Value = Decimal.Parse(template.Properties["allowedTimeDiff"][0].Values[0]);
        }
Ejemplo n.º 10
0
        // ====

        /// <summary>
        /// Parses an AiTemplate file, loading all of its objects into the ObjectManager
        /// </summary>
        /// <param name="FilePath">The full path to the extracted AiTemplate.ai file</param>
        public static void Parse(AiFile ConFile)
        {
            // Split our contents into an object araray
            IEnumerable <Token> FileTokens = Tokenize(
                String.Join(Environment.NewLine, File.ReadAllLines(ConFile.FilePath).Where(x => !String.IsNullOrWhiteSpace(x)))
                );

            // Create our needed objects
            RemComment Comment = new RemComment();

            // Create an empty object template
            ObjectTemplate template = new ObjectTemplate();

            // Add our file objects
            ConFile.Objects = new Dictionary <string, ObjectTemplate>();

            // proceed
            foreach (Token Tkn in FileTokens)
            {
                // Clean line up
                string TokenValue = Tkn.Value.TrimStart().TrimEnd(Environment.NewLine.ToCharArray());

                // Handle Rem Comments
                if (Tkn.Kind == RemComment)
                {
                    StringBuilder CommentBuilder = new StringBuilder();
                    CommentBuilder.AppendLine(TokenValue);
                    Comment.Position = Tkn.Position;
                    Comment.Value   += CommentBuilder.ToString();
                }

                // Handle Object Starts
                else if (Tkn.Kind == ObjectStart)
                {
                    // Split line into function call followed by and arguments
                    string[] funcArgs = TokenValue.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                    // Get function info [0] => templateName [1] => methodOrVariable
                    string[] funcInfo = funcArgs[0].Split(new char[] { '.' });

                    // Get our template type
                    TemplateType Type = (TemplateType)Enum.Parse(typeof(TemplateType), funcInfo[0], true);

                    // Create the new object
                    template      = (Type == TemplateType.AiTemplate) ? new AiTemplate() : new ObjectTemplate();
                    template.Name = funcArgs.Last();
                    template.TemplateTypeString = funcInfo[0];
                    template.ObjectType         = (funcArgs.Length > 2) ? funcArgs[1] : "";
                    template.TemplateType       = Type;
                    template.Comment            = Comment;
                    template.Position           = Tkn.Position;
                    template.Properties         = new Dictionary <string, List <ObjectProperty> >();
                    template.File = ConFile;

                    // Add object to our objects array, and our object manager
                    ConFile.Objects.Add(template.Name, template);
                    ObjectManager.RegisterObject(template.Name, ConFile);

                    // Reset comment
                    Comment = new RemComment();
                }

                // handle properties
                else if (Tkn.Kind == ObjectProperty)
                {
                    // Split line into function call followed by and arguments
                    string[] funcArgs = TokenValue.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                    // Get function info [0] => templateName [1] => methodOrVariable
                    string[] funcInfo = funcArgs[0].Split(new char[] { '.' });

                    // Sub object?
                    if (funcInfo[1] == "addPlugIn")
                    {
                        // Throw an exception if we are invalidly adding a plugin
                        if (template.TemplateType != TemplateType.AiTemplate)
                        {
                            throw new Exception("Attempting to add a plugin to object type: " + template.TemplateType.ToString());
                        }

                        // Fetch the plugin
                        ObjectTemplate plugin = ObjectManager.GetObjectByName(funcArgs[1]);

                        // Add template plugin
                        (template as AiTemplate).Plugins.Add(
                            (AiTemplatePluginType)Enum.Parse(typeof(AiTemplatePluginType), plugin.ObjectType, true),
                            plugin
                            );
                    }

                    // Create the object property
                    ObjectProperty prop = new ObjectProperty()
                    {
                        Name     = funcInfo[1],
                        Comment  = Comment,
                        Position = Tkn.Position,
                        Values   = funcArgs.Skip(1).ToArray(),
                    };

                    // Add template property if we dont have one
                    if (!template.Properties.ContainsKey(funcInfo[1]))
                    {
                        template.Properties.Add(funcInfo[1], new List <ObjectProperty>());
                    }

                    // Add the porperty
                    template.Properties[funcInfo[1]].Add(prop);

                    // Reset comment
                    Comment = new RemComment();
                }
            }
        }